Skip to content

Commit

Permalink
passes cookies on. fixes #188
Browse files Browse the repository at this point in the history
  • Loading branch information
litlfred committed Sep 12, 2014
1 parent 87d7768 commit 48d53b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"cookie" : "0.1.2",
"mongodb": "1.4.7",
"koa": "0.5.2",
"koa-route": "~1.0.2",
Expand Down
22 changes: 22 additions & 0 deletions src/middleware/router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ config = require '../config/config'
config.mongo = config.get('mongo')
logger = require "winston"
status = require "http-status"
cookie = require 'cookie'



containsMultiplePrimaries = (routes) ->
numPrimaries = 0
Expand Down Expand Up @@ -106,6 +109,8 @@ sendHttpRequest = (ctx, responseDst, options, secured, callback) ->
responseDst.header = {}
for key, value of routeRes.headers
switch key
when 'set-cookie'
setCookiesOnContext ctx, value
when 'location' then responseDst.redirect(value)
else responseDst.header[key] = value

Expand Down Expand Up @@ -150,6 +155,23 @@ sendHttpRequest = (ctx, responseDst, options, secured, callback) ->

routeReq.end()



setCookiesOnContext = (ctx,value) ->
for c_key,c_value in value
c_opts = {path:false,httpOnly:false} #clear out default values in cookie module
c_vals = {}
for p_key,p_val of cookie.parse c_key
p_key_l = p_key.toLowerCase()
switch p_key_l
when 'max-age' then c_opts['maxage'] = parseInt p_val, 10
when 'expires' then c_opts['expires'] = new Date p_val
when 'path','domain','secure','signed','overwrite' then c_opts[p_key_l] = p_val
when 'httponly' then c_opts['httpOnly'] = p_val
else c_vals[p_key] = p_val
for p_key,p_val of c_vals
ctx.cookies.set p_key,p_val,c_opts

sendSocketRequest = (ctx, responseDst, options, secured, callback) ->
requestBody = ctx.body
client = new net.Socket()
Expand Down

0 comments on commit 48d53b2

Please sign in to comment.