Giter VIP home page Giter VIP logo

node-cookie-store's Introduction

Build Status Coverage

cookie-store

An RFC-6265 cookie store to implement the mechanism of HTTP cookie and Set-Cookie header fields as a browser does.

  • A central store for different domains and paths
  • Set cookies as if from a certain domain and path
  • Get cookies as if from a certain domain and path

Install

$ npm install cookie-store

Usage

const CookieStore = require('cookie-store')
const cs = new CookieStore()

const handler = cs.from({
  domain: 'bar.foo.com',
  path: '/a'
})

handler.set('foo', 'a', {
  domain: '.foo.com'
})

handler.get('foo').value
// 'a'

cs.from({domain, path, http}) : Handler

  • domain String
  • path String
  • http Boolean=true indicate that we will manipulate cookie via HTTP APIs. Defaults to true

Returns Handler the cookie handler for specific domain and path.

cs.restart()

Restarts the cookie store, and filters out session cookies.

handler.set(key, value, options)

  • key String
  • value String
  • options Object=
    • domain String= Optional. If not specified, the cookie's host-only-flag will be set to true
    • path String= Optional. If not specified, it will
    • httpOnly Boolean=false whether set the cookie's http-only-flag to true
    • maxAge Number
    • expires Date|TimeStamp

Set a cookie.

Returns

  • Cookie if it has succeeded to set the cookie
  • null if it fails to set the cookie

handler.setCookie(setCookieHeader)

  • setCookieHeader String the value of the HTTP Set-Cookie header.

Set a cookie via HTTP Set-Cookie header.

Returns Cookie|null as well as handler.set()

handler.getAll(name)

Returns Array.<Cookie> all matched cookies which have name name.

handler.get(name)

  • name String

Searches and returns the most matching cookie according to the sorting rule: https://tools.ietf.org/html/rfc6265#section-5.4

Returns

  • Cookie if an available cookie is found
  • null if no matched cookie.

handler.remove(name)

Removes all matched cookies of the name name.

handler.toHeader()

Returns String the value of HTTP Cookie header

Struct: Cookie

  • name
  • value
  • domain
  • path
  • httpOnly
  • hostOnly
  • persistent
  • expiryTime

The RFC-6265 cookie object.

License

MIT

node-cookie-store's People

Contributors

kaelzhang avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.