Skip to content

Commit

Permalink
Set JSESSIONID cookie unconditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
majek committed Aug 18, 2011
1 parent 0dda494 commit bb298a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/sockjs.coffee
Expand Up @@ -48,17 +48,17 @@ class Server extends events.EventEmitter

p = (s) => new RegExp('^' + options.prefix + s + '[/]?$')
t = (s) => [p('/([^/.]+)/([^/.]+)' + s), 'server', 'session']
opts_filters = ['xhr_cors', 'xhr_options', 'cache_for', 'expose']
opts_filters = ['h_sid', 'xhr_cors', 'xhr_options', 'cache_for', 'expose']
dispatcher = [
['GET', p(''), ['welcome_screen']],
['GET', p('/iframe[0-9-.a-z_]*.html'), ['iframe', 'cache_for', 'expose']],
['GET', t('/jsonp'), ['h_no_cache','jsonp']],
['POST',t('/jsonp_send'), ['expect_form', 'jsonp_send']],
['POST', t('/xhr'), ['xhr_cors', 'xhr_poll']],
['GET', t('/jsonp'), ['h_sid', 'h_no_cache','jsonp']],
['POST',t('/jsonp_send'), ['h_sid', 'expect_form', 'jsonp_send']],
['POST', t('/xhr'), ['h_sid', 'xhr_cors', 'xhr_poll']],
['OPTIONS', t('/xhr'), opts_filters],
['POST', t('/xhr_send'), ['xhr_cors', 'expect_xhr', 'xhr_send']],
['POST', t('/xhr_send'), ['h_sid', 'xhr_cors', 'expect_xhr', 'xhr_send']],
['OPTIONS', t('/xhr_send'), opts_filters],
['POST', t('/xhr_streaming'), ['xhr_cors', 'xhr_streaming']],
['POST', t('/xhr_streaming'), ['h_sid', 'xhr_cors', 'xhr_streaming']],
['OPTIONS', t('/xhr_streaming'), opts_filters],
]
maybe_add_transport = (name, urls) ->
Expand All @@ -71,7 +71,7 @@ class Server extends events.EventEmitter
maybe_add_transport('websocket',[
['GET', t('/websocket'), ['websocket']]])
maybe_add_transport('eventsource',[
['GET', t('/eventsource'), ['h_no_cache', 'eventsource']]])
['GET', t('/eventsource'), ['h_sid', 'h_no_cache', 'eventsource']]])
webjs_handler = new webjs.WebJS(app, dispatcher)

install_handler = (ee, event, handler) ->
Expand Down
12 changes: 12 additions & 0 deletions src/webjs.coffee
@@ -1,6 +1,7 @@
url = require('url')
querystring = require('querystring')
fs = require('fs')
uuid = require('node-uuid')

$ = require('jquery');

Expand Down Expand Up @@ -196,3 +197,14 @@ exports.generic_app =
q = undefined
next_filter(q)
throw {status:0}

h_sid: (req, res, data) ->
req.cookies = {}
if req.headers.cookie
for cookie in req.headers.cookie.split(';')
parts = cookie.split('=')
req.cookies[ parts[0].trim() ] = ( parts[1] || '' ).trim()
if res.setHeader
jsid = req.cookies['JSESSIONID'] or uuid()
res.setHeader('Set-Cookie', 'JSESSIONID=' + jsid + '; HttpOnly; path=/')
return data

0 comments on commit bb298a4

Please sign in to comment.