Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
31 lines (24 sloc) 1.04 KB
utils = require('./utils')
websocket_hixie76 = require('./trans-websocket-hixie76')
websocket_hybi10 = require('./trans-websocket-hybi10') =
websocket: (req, connection, head) ->
if (req.headers.upgrade || '').toLowerCase() isnt 'websocket'
throw {
status: 406
message: "Can upgrade only to websockets."
origin = req.headers.origin
if not utils.verify_origin(origin,
throw {
status: 403
message: "Unverified origin."
location = (if origin and origin[0...5] is 'https' then 'wss' else 'ws')
location += '://' + + req.url
ver = req.headers['sec-websocket-version']
if ver is '8' or ver is '7'
new websocket_hybi10.WebHandshake8(req, connection, head or '', origin, location)
new websocket_hixie76.WebHandshakeHixie76(req, connection, head or '', origin, location)
return true
Jump to Line
Something went wrong with that request. Please try again.