Skip to content

Commit

Permalink
fix websocket bug, Issue #26
Browse files Browse the repository at this point in the history
  • Loading branch information
chemhack committed May 16, 2013
1 parent 25d9b7f commit f005641
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions lib/server.js
Expand Up @@ -29,18 +29,26 @@ var SPDYProxy = function(options) {

function synReply(socket, code, reason, headers, cb) {
try {
socket._lock(function() {
var socket = this;

this._framer.replyFrame(
this.id, code, reason, headers,
function (err, frame) {
socket.connection.write(frame);
socket._unlock();
cb.call();
}
);
});
if(socket._lock){ //SPDY socket
socket._lock(function() {
var socket = this;
this._framer.replyFrame(
this.id, code, reason, headers,
function (err, frame) {
socket.connection.write(frame);
socket._unlock();
cb.call();
}
);
});
}else{ //raw SSL socket
var statusLine = 'HTTP/1.1 ' + code + ' ' + reason + '\r\n';
var headerLines='';
for(key in headers){
headerLines+=key+': '+headers[key]+'\r\n';
}
socket.write(statusLine+headerLines+'\r\n','UTF-8',cb);
}
} catch(error) {
cb.call();
}
Expand Down

0 comments on commit f005641

Please sign in to comment.