Advertisement
stuppid_bot

Node.js cookies.js module

Sep 4th, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. qs = require('querystring');
  2.  
  3. exports.getCookies = function(req) {
  4.     if ('cookie' in req.headers)
  5.         return qs.parse(req.headers['cookie'], '; ');
  6. };
  7.  
  8. exports.setCookie = function(res, name, value, expires, path, domain, secure, httponly) {
  9.     var _ = res.getHeader('set-cookie');
  10.     _ = _ ? [].concat(_) : [];
  11.     _.push(qs.escape(name) + '=' + qs.escape(value) + (expires === undefined ? '' : '; Expires=' + new Date(expires).toUTCString()) + (path ? '; Path=' + path : '') + (domain ? '; Domain=' + domain : '') + (secure ? '; Secure' : '') + (httponly ? '; HttpOnly' : ''));
  12.     res.setHeader('set-cookie', _);
  13. };
  14.  
  15. exports.deleteCookie = function(res, name, path, domain) {
  16.     this.setCookie(name, '', 0, path, domain);
  17. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement