Skip to content

Commit

Permalink
websocket.Connection: Tyding things up
Browse files Browse the repository at this point in the history
* Using the new sendHeader format from patches

!! Now works with Google Chrome native WebSocket implementation.

* .request is also now available for cookie tracking and stuff
  • Loading branch information
Jonas Pfenniger committed Dec 27, 2009
1 parent 18be4a5 commit 57c5c6a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/http/websocket.js
Expand Up @@ -18,6 +18,9 @@ function Connection(request, response) {
var self = this,
conn = this.connection = request.connection;

this.request = request;
this.remoteAddress = conn.remoteAddress;

// TODO: fail differently if not compatible ?
if (!supportUpgrade(request)) {
conn.close();
Expand All @@ -31,8 +34,6 @@ function Connection(request, response) {
conn.close();
});

this.remoteAddress = conn.remoteAddress;

request.addListener("complete", function() {
// Hijack connection after handshake
conn.hijack();
Expand All @@ -48,10 +49,11 @@ function Connection(request, response) {
});

response.use_chunked_encoding_by_default = false;
response.sendHeader(101, {
response.sendHeader([101, "Web Socket Protocol Handshake"], {
"Upgrade": "WebSocket",
"Connection": "Upgrade",
"WebSocket-Origin": request.headers.origin,
// TODO: wss://
"WebSocket-Location": "ws://" + request.headers.host + request.uri.path
});
response.flush(); // send!!
Expand Down

0 comments on commit 57c5c6a

Please sign in to comment.