pax_global_header00006660000000000000000000000064123236056130014513gustar00rootroot0000000000000052 comment=244dabd7bc3e2d3482b121c816b4b4e034822b6f cookie-0.1.2/000077500000000000000000000000001232360561300127645ustar00rootroot00000000000000cookie-0.1.2/.gitignore000066400000000000000000000000151232360561300147500ustar00rootroot00000000000000node_modules cookie-0.1.2/.npmignore000066400000000000000000000000211232360561300147540ustar00rootroot00000000000000test .travis.yml cookie-0.1.2/.travis.yml000066400000000000000000000001001232360561300150640ustar00rootroot00000000000000language: node_js node_js: - "0.6" - "0.8" - "0.10" cookie-0.1.2/LICENSE000066400000000000000000000021021232360561300137640ustar00rootroot00000000000000// MIT License Copyright (C) Roman Shtylman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cookie-0.1.2/README.md000066400000000000000000000021351232360561300142440ustar00rootroot00000000000000# cookie [![Build Status](https://secure.travis-ci.org/defunctzombie/node-cookie.png?branch=master)](http://travis-ci.org/defunctzombie/node-cookie) # cookie is a basic cookie parser and serializer. It doesn't make assumptions about how you are going to deal with your cookies. It basically just provides a way to read and write the HTTP cookie headers. See [RFC6265](http://tools.ietf.org/html/rfc6265) for details about the http header for cookies. ## how? ``` npm install cookie ``` ```javascript var cookie = require('cookie'); var hdr = cookie.serialize('foo', 'bar'); // hdr = 'foo=bar'; var cookies = cookie.parse('foo=bar; cat=meow; dog=ruff'); // cookies = { foo: 'bar', cat: 'meow', dog: 'ruff' }; ``` ## more The serialize function takes a third parameter, an object, to set cookie options. See the RFC for valid values. ### path > cookie path ### expires > absolute expiration date for the cookie (Date object) ### maxAge > relative max age of the cookie from when the client receives it (seconds) ### domain > domain for the cookie ### secure > true or false ### httpOnly > true or false cookie-0.1.2/index.js000066400000000000000000000037531232360561300144410ustar00rootroot00000000000000 /// Serialize the a name value pair into a cookie string suitable for /// http headers. An optional options object specified cookie parameters /// /// serialize('foo', 'bar', { httpOnly: true }) /// => "foo=bar; httpOnly" /// /// @param {String} name /// @param {String} val /// @param {Object} options /// @return {String} var serialize = function(name, val, opt){ opt = opt || {}; var enc = opt.encode || encode; var pairs = [name + '=' + enc(val)]; if (null != opt.maxAge) { var maxAge = opt.maxAge - 0; if (isNaN(maxAge)) throw new Error('maxAge should be a Number'); pairs.push('Max-Age=' + maxAge); } if (opt.domain) pairs.push('Domain=' + opt.domain); if (opt.path) pairs.push('Path=' + opt.path); if (opt.expires) pairs.push('Expires=' + opt.expires.toUTCString()); if (opt.httpOnly) pairs.push('HttpOnly'); if (opt.secure) pairs.push('Secure'); return pairs.join('; '); }; /// Parse the given cookie header string into an object /// The object has the various cookies as keys(names) => values /// @param {String} str /// @return {Object} var parse = function(str, opt) { opt = opt || {}; var obj = {} var pairs = str.split(/; */); var dec = opt.decode || decode; pairs.forEach(function(pair) { var eq_idx = pair.indexOf('=') // skip things that don't look like key=value if (eq_idx < 0) { return; } var key = pair.substr(0, eq_idx).trim() var val = pair.substr(++eq_idx, pair.length).trim(); // quoted values if ('"' == val[0]) { val = val.slice(1, -1); } // only assign once if (undefined == obj[key]) { try { obj[key] = dec(val); } catch (e) { obj[key] = val; } } }); return obj; }; var encode = encodeURIComponent; var decode = decodeURIComponent; module.exports.serialize = serialize; module.exports.parse = parse; cookie-0.1.2/package.json000066400000000000000000000007561232360561300152620ustar00rootroot00000000000000{ "author": "Roman Shtylman ", "name": "cookie", "description": "cookie parsing and serialization", "version": "0.1.2", "repository": { "type": "git", "url": "git://github.com/shtylman/node-cookie.git" }, "keywords": [ "cookie", "cookies" ], "main": "index.js", "scripts": { "test": "mocha" }, "dependencies": {}, "devDependencies": { "mocha": "1.x.x" }, "optionalDependencies": {}, "engines": { "node": "*" } } cookie-0.1.2/test/000077500000000000000000000000001232360561300137435ustar00rootroot00000000000000cookie-0.1.2/test/mocha.opts000066400000000000000000000000131232360561300157330ustar00rootroot00000000000000--ui qunit cookie-0.1.2/test/parse.js000066400000000000000000000031641232360561300154170ustar00rootroot00000000000000 var assert = require('assert'); var cookie = require('..'); suite('parse'); test('basic', function() { assert.deepEqual({ foo: 'bar' }, cookie.parse('foo=bar')); assert.deepEqual({ foo: '123' }, cookie.parse('foo=123')); }); test('ignore spaces', function() { assert.deepEqual({ FOO: 'bar', baz: 'raz' }, cookie.parse('FOO = bar; baz = raz')); }); test('escaping', function() { assert.deepEqual({ foo: 'bar=123456789&name=Magic+Mouse' }, cookie.parse('foo="bar=123456789&name=Magic+Mouse"')); assert.deepEqual({ email: ' ",;/' }, cookie.parse('email=%20%22%2c%3b%2f')); }); test('ignore escaping error and return original value', function() { assert.deepEqual({ foo: '%1', bar: 'bar' }, cookie.parse('foo=%1;bar=bar')); }); test('ignore non values', function() { assert.deepEqual({ foo: '%1', bar: 'bar' }, cookie.parse('foo=%1;bar=bar;HttpOnly;Secure')); }); test('unencoded', function() { assert.deepEqual({ foo: 'bar=123456789&name=Magic+Mouse' }, cookie.parse('foo="bar=123456789&name=Magic+Mouse"',{ decode: function(value) { return value; } })); assert.deepEqual({ email: '%20%22%2c%3b%2f' }, cookie.parse('email=%20%22%2c%3b%2f',{ decode: function(value) { return value; } })); }); test('dates', function() { assert.deepEqual({ priority: 'true', Path: '/', expires: 'Wed, 29 Jan 2014 17:43:25 GMT' }, cookie.parse('priority=true; expires=Wed, 29 Jan 2014 17:43:25 GMT; Path=/',{ decode: function(value) { return value; } })); }) cookie-0.1.2/test/serialize.js000066400000000000000000000031761232360561300162770ustar00rootroot00000000000000// builtin var assert = require('assert'); var cookie = require('..'); suite('serialize'); test('basic', function() { assert.equal('foo=bar', cookie.serialize('foo', 'bar')); assert.equal('foo=bar%20baz', cookie.serialize('foo', 'bar baz')); }); test('path', function() { assert.equal('foo=bar; Path=/', cookie.serialize('foo', 'bar', { path: '/' })); }); test('secure', function() { assert.equal('foo=bar; Secure', cookie.serialize('foo', 'bar', { secure: true })); assert.equal('foo=bar', cookie.serialize('foo', 'bar', { secure: false })); }); test('domain', function() { assert.equal('foo=bar; Domain=example.com', cookie.serialize('foo', 'bar', { domain: 'example.com' })); }); test('httpOnly', function() { assert.equal('foo=bar; HttpOnly', cookie.serialize('foo', 'bar', { httpOnly: true })); }); test('maxAge', function() { assert.equal('foo=bar; Max-Age=1000', cookie.serialize('foo', 'bar', { maxAge: 1000 })); assert.equal('foo=bar; Max-Age=0', cookie.serialize('foo', 'bar', { maxAge: 0 })); }); test('escaping', function() { assert.deepEqual('cat=%2B%20', cookie.serialize('cat', '+ ')); }); test('parse->serialize', function() { assert.deepEqual({ cat: 'foo=123&name=baz five' }, cookie.parse( cookie.serialize('cat', 'foo=123&name=baz five'))); assert.deepEqual({ cat: ' ";/' }, cookie.parse( cookie.serialize('cat', ' ";/'))); }); test('unencoded', function() { assert.deepEqual('cat=+ ', cookie.serialize('cat', '+ ', { encode: function(value) { return value; } })); })