Permalink
Browse files

websocket.Connection: Tyding things up

* 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...
1 parent 18be4a5 commit 57c5c6a4bed5427ca0b021455789827c6933f2bb @zimbatm committed Dec 27, 2009
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/http/websocket.js
View
8 lib/http/websocket.js
@@ -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();
@@ -31,8 +34,6 @@ function Connection(request, response) {
conn.close();
});
- this.remoteAddress = conn.remoteAddress;
-
request.addListener("complete", function() {
// Hijack connection after handshake
conn.hijack();
@@ -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!!

0 comments on commit 57c5c6a

Please sign in to comment.