Skip to content

Commit

Permalink
Merge pull request websockets#94 from guille/add/headers-hook
Browse files Browse the repository at this point in the history
Headers hook
  • Loading branch information
einaros committed Jul 3, 2012
2 parents 41084f1 + 3ecdb99 commit 6394681
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/ws.md
Expand Up @@ -37,6 +37,12 @@ When the Upgrade was successfully, the `callback` will be called with a `ws.WebS

If the underlying server emits an error, it will be forwarded here.

### Event: 'headers'

`function (headers) { }`

Emitted with the object of HTTP headers that are going to be written to the `Stream` as part of the handshake.

### Event: 'connection'

`function (socket) { }`
Expand Down
3 changes: 3 additions & 0 deletions lib/WebSocketServer.js
Expand Up @@ -196,6 +196,9 @@ function handleHybiUpgrade(req, socket, upgradeHead, cb) {
headers['Sec-WebSocket-Protocol'] = protocol;
}

// allows external modification/inspection of handshake headers
self.emit('headers', headers);

socket.setTimeout(0);
socket.setNoDelay(true);
try {
Expand Down

0 comments on commit 6394681

Please sign in to comment.