Permalink
Browse files

Merge pull request #7 from kriszyp/master

Fix node request adaptor
  • Loading branch information...
2 parents bd55a1d + 3455ff8 commit 2129c0dd1f64ae6815413753df9ab8a2cab9866e @kriszyp kriszyp committed Aug 22, 2012
Showing with 25 additions and 18 deletions.
  1. +4 −1 jsgi-node.js
  2. +21 −17 jsgi/node.js
View
@@ -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);
}
View
@@ -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(){
@@ -36,7 +38,9 @@ exports.Node = function(nodeApp){
resume: function(){
}
- },
+ }
+ nodeRequest.on = nodeRequest.addListener;
+ nodeApp(nodeRequest,
{
writeHead: function(status, headers){
var write;

0 comments on commit 2129c0d

Please sign in to comment.