{"action":"closed","issue":{"url":"https://api.github.com/repos/mpneuried/connect-redis-sessions/issues/13","repository_url":"https://api.github.com/repos/mpneuried/connect-redis-sessions","labels_url":"https://api.github.com/repos/mpneuried/connect-redis-sessions/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/mpneuried/connect-redis-sessions/issues/13/comments","events_url":"https://api.github.com/repos/mpneuried/connect-redis-sessions/issues/13/events","html_url":"https://github.com/mpneuried/connect-redis-sessions/issues/13","id":166759532,"number":13,"title":"it fails to writeHead for cookie","user":{"login":"wootaek-py","id":17694447,"avatar_url":"https://avatars.githubusercontent.com/u/17694447?v=3","gravatar_id":"","url":"https://api.github.com/users/wootaek-py","html_url":"https://github.com/wootaek-py","followers_url":"https://api.github.com/users/wootaek-py/followers","following_url":"https://api.github.com/users/wootaek-py/following{/other_user}","gists_url":"https://api.github.com/users/wootaek-py/gists{/gist_id}","starred_url":"https://api.github.com/users/wootaek-py/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wootaek-py/subscriptions","organizations_url":"https://api.github.com/users/wootaek-py/orgs","repos_url":"https://api.github.com/users/wootaek-py/repos","events_url":"https://api.github.com/users/wootaek-py/events{/privacy}","received_events_url":"https://api.github.com/users/wootaek-py/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mpneuried/connect-redis-sessions/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/mpneuried/connect-redis-sessions/labels/TODO","name":"TODO","color":"0e8a16"}],"state":"closed","locked":false,"assignee":{"login":"mpneuried","id":300631,"avatar_url":"https://avatars.githubusercontent.com/u/300631?v=3","gravatar_id":"","url":"https://api.github.com/users/mpneuried","html_url":"https://github.com/mpneuried","followers_url":"https://api.github.com/users/mpneuried/followers","following_url":"https://api.github.com/users/mpneuried/following{/other_user}","gists_url":"https://api.github.com/users/mpneuried/gists{/gist_id}","starred_url":"https://api.github.com/users/mpneuried/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpneuried/subscriptions","organizations_url":"https://api.github.com/users/mpneuried/orgs","repos_url":"https://api.github.com/users/mpneuried/repos","events_url":"https://api.github.com/users/mpneuried/events{/privacy}","received_events_url":"https://api.github.com/users/mpneuried/received_events","type":"User","site_admin":false},"assignees":[{"login":"mpneuried","id":300631,"avatar_url":"https://avatars.githubusercontent.com/u/300631?v=3","gravatar_id":"","url":"https://api.github.com/users/mpneuried","html_url":"https://github.com/mpneuried","followers_url":"https://api.github.com/users/mpneuried/followers","following_url":"https://api.github.com/users/mpneuried/following{/other_user}","gists_url":"https://api.github.com/users/mpneuried/gists{/gist_id}","starred_url":"https://api.github.com/users/mpneuried/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpneuried/subscriptions","organizations_url":"https://api.github.com/users/mpneuried/orgs","repos_url":"https://api.github.com/users/mpneuried/repos","events_url":"https://api.github.com/users/mpneuried/events{/privacy}","received_events_url":"https://api.github.com/users/mpneuried/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2016-07-21T08:00:22Z","updated_at":"2016-07-26T09:41:44Z","closed_at":"2016-07-26T09:41:44Z","body":"bellow is simple testing code using express 4.14.0\r\n\r\n\r\nindex.js\r\n```js\r\n{\r\n\r\n\t/* package.json\r\n\t{\r\n\t  \"name\": \"test_session\",\r\n\t  \"version\": \"1.0.0\",\r\n\t  \"description\": \"\",\r\n\t  \"main\": \"index.js\",\r\n\t  \"author\": \"\",\r\n\t  \"license\": \"ISC\",\r\n\t  \"dependencies\": {\r\n\t\t\"connect-redis-sessions\": \"^1.2.0\",\r\n\t\t\"cookie-parser\": \"^1.4.3\",\r\n\t\t\"express\": \"^4.14.0\"\r\n\t  }\r\n\t}\r\n\r\n\t*/\r\n\r\n\t// get the modules \r\n\tvar http = require('http');\r\n\tvar express = require( \"express\" );\r\n\tvar cookieParser = require( \"cookie-parser\" );\r\n\tvar ConnectRedisSessions = require( \"connect-redis-sessions\" );\r\n\tvar app = express();\r\n\t \r\n\t \r\n\t// configute express \r\n\tapp\r\n\t\t.use( express.query() )\r\n\t\t.use( cookieParser() )\r\n\t\t.use( ConnectRedisSessions( { app: \"myappname\"} ) )\r\n\t \r\n\t// listen for requests \r\n\tapp.use( function( req, res ){\r\n\t\t\r\n\t\tconsole.log( '> req.session.id:',  req.session.id ); // <--- always null\r\n\t\t\r\n\t\t// ------ this code fails to write cookie -----------\r\n\t\treq.session.upgrade( 7 );\r\n\t\tres.end( \"Hello express redis sessions\" );\r\n\t\t\r\n\t\t/* ------ this code works good -----------\r\n\t\treq.session.upgrade( 7, (err) => {\r\n\t\t\tres.end( \"Hello express redis sessions\" );\r\n\t\t} );\r\n\t\t*/\r\n\t\t\r\n\t\t\r\n\t});\r\n\r\n\r\n\tconst server = http.createServer( app );\r\n\tserver.listen( '80' );\r\n\r\n}\r\n```\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/node_modules/connect-redis-sessions/lib/sessionhandler.js\r\n```js\r\n{\r\n\r\n\tSessionHandler.prototype.generate = function (req, token, id, ttl) {\r\n\r\n\t\t  console.log( \"@ generate:\", token, id, ttl );\r\n\r\n\t\t  var res, _writeHead;\r\n\t\t  req.sessionID = token;\r\n\t\t  req.session = new SessionObject( this, req, this._redisToSession( {\r\n\t\t\t  id: id,\r\n\t\t\t  ttl: ttl,\r\n\t\t\t  ip: this._getRequestIP( req )\r\n\t\t  } ) );\r\n\t\t  res = req.res;\r\n\r\n\t\t  _writeHead = res.writeHead;\r\n\r\n\t\t  res.writeHead = (function (_this) {\r\n\r\n\t\t\t  console.log( \"@ res.writeHead()\" );\r\n\r\n\t\t\t  // @@@@@@@ problem is this part @@@@@@@\r\n\t\t\t  // bellow function never runs when callback function is null\r\n\t\t\t  return function () {\r\n\t\t\t\t  _this._setCookie( req );\r\n\t\t\t\t  _writeHead.apply( res, arguments );\r\n\t\t\t  };\r\n\t\t  })( this );\r\n\t  };\r\n\r\n}\r\n```\r\n\r\n\r\n"}}
{"actor":{"display_login":"mpneuried"}}