Skip to content

Commit

Permalink
Merge pull request #7 from kriszyp/master
Browse files Browse the repository at this point in the history
Fix node request adaptor
  • Loading branch information
kriszyp committed Aug 22, 2012
2 parents bd55a1d + 3455ff8 commit 2129c0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
5 changes: 4 additions & 1 deletion jsgi-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,14 @@ function Response( response, stream ) {
}
try{
// if it is not too late, set the status
response.writeHead(500, {});
if(!response.statusCode){
response.writeHead(500, {});
}
}catch(e2){}
try{
response.write( "Error: " + e.stack );
response.end();
console.log("error",e);
}catch(e3){
sys.puts(e3.stack);
}
Expand Down
38 changes: 21 additions & 17 deletions jsgi/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@ exports.Node = function(nodeApp){
var endListeners = [];
var bodyDeferred;
var responseDeferred = defer();
nodeApp({
var nodeRequest = {
headers: request.headers,
httpVersionMajor: request.version[0],
httpVersionMinor: request.version[1],
addListener: function(event, callback){
if(event == "data"){
when(request.body && request.body.forEach(function(data){
callback(data);
}), function(){
endListeners.forEach(function(listener){
listener();
process.nextTick(function(){
if(event == "data"){
when(request.body && request.body.forEach(function(data){
callback(data);
}), function(){
endListeners.forEach(function(listener){
listener();
});
endListeners = null;
});
endListeners = null;
});
}
if(event == "end"){
if(endListeners){
endListeners.push(callback);
}else{
callback();
}
}
if(event == "end"){
if(endListeners){
endListeners.push(callback);
}else{
callback();
}
}
});
return this;
},
pause: function(){
Expand All @@ -36,7 +38,9 @@ exports.Node = function(nodeApp){
resume: function(){

}
},
}
nodeRequest.on = nodeRequest.addListener;
nodeApp(nodeRequest,
{
writeHead: function(status, headers){
var write;
Expand Down

0 comments on commit 2129c0d

Please sign in to comment.