Skip to content

Commit

Permalink
Simplify headers transfer
Browse files Browse the repository at this point in the history
Write 500 status if not too late during error of forEach of body
  • Loading branch information
kriszyp committed Aug 11, 2010
1 parent 00a2f13 commit 3b3307c
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions lib/jsgi-node.js
Expand Up @@ -39,6 +39,7 @@ function Request( request ) {
var questionIndex = url.indexOf("?");
this.method = request.method;
this.nodeRequest = request;
this.headers = request.headers;
if(questionIndex > -1){
this.pathInfo = url.substring(0, questionIndex);
this.queryString = url.substring(questionIndex + 1);
Expand Down Expand Up @@ -69,30 +70,16 @@ Request.prototype = {
scriptName: "",
scheme:"http",
get host(){
var host = this.nodeRequest.headers.host;
var host = this.headers.host;
return host ? host.split(":")[0] : "";
},
get port(){
var host = this.nodeRequest.headers.host;
var host = this.headers.host;
return host ? (host.split(":")[1] || 80) : 80;
},
get remoteAddr(){
return this.nodeRequest.connection.remoteAddress;
},
get headers(){
if(this._headers){
return this._headers;
}
var headers = this.nodeRequest.headers;
var lowerCaseHeaders = {};
for(var i in headers){
lowerCaseHeaders[i.toLowerCase()] = headers[i];
}
return this._headers = lowerCaseHeaders;
},
set headers(value){
this._headers = value;
},
get version(){
return [ this.nodeRequest.httpVersionMajor, this.nodeRequest.httpVersionMinor ]
}
Expand Down Expand Up @@ -200,6 +187,10 @@ function Response( response, stream ) {
if(canceller){
stream.addListener("close", canceller);
}
try{
// if it is not too late, set the status
response.writeHead(500, {});
}catch(e2){}
response.write( "Error: " + e.stack );
response.end();
}
Expand Down

0 comments on commit 3b3307c

Please sign in to comment.