pax_global_header00006660000000000000000000000064121402651440014511gustar00rootroot0000000000000052 comment=ccea5901180fc9c4c2c73bd4a445903faf7b1163 node-cookie-0.1.0/000077500000000000000000000000001214026514400137035ustar00rootroot00000000000000node-cookie-0.1.0/.gitignore000066400000000000000000000000151214026514400156670ustar00rootroot00000000000000node_modules node-cookie-0.1.0/.travis.yml000066400000000000000000000001001214026514400160030ustar00rootroot00000000000000language: node_js node_js: - "0.6" - "0.8" - "0.10" node-cookie-0.1.0/LICENSE000066400000000000000000000021021214026514400147030ustar00rootroot00000000000000// 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. node-cookie-0.1.0/README.md000066400000000000000000000021231214026514400151600ustar00rootroot00000000000000# cookie [![Build Status](https://secure.travis-ci.org/shtylman/node-cookie.png?branch=master)](http://travis-ci.org/shtylman/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 node-cookie-0.1.0/index.js000066400000000000000000000035531214026514400153560ustar00rootroot00000000000000 /// 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 (opt.maxAge) pairs.push('Max-Age=' + opt.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; node-cookie-0.1.0/package.json000066400000000000000000000007561214026514400162010ustar00rootroot00000000000000{ "author": "Roman Shtylman ", "name": "cookie", "description": "cookie parsing and serialization", "version": "0.1.0", "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": "*" } } node-cookie-0.1.0/test/000077500000000000000000000000001214026514400146625ustar00rootroot00000000000000node-cookie-0.1.0/test/mocha.opts000066400000000000000000000000131214026514400166520ustar00rootroot00000000000000--ui qunit node-cookie-0.1.0/test/parse.js000066400000000000000000000025171214026514400163370ustar00rootroot00000000000000 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; } })); }) node-cookie-0.1.0/test/serialize.js000066400000000000000000000030321214026514400172050ustar00rootroot00000000000000// 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 })); }); 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; } })); })