Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplify headers transfer

Write 500 status if not too late during error of forEach of body
  • Loading branch information...
commit 3b3307cc53f82d5dc810e8c23e0c1f9313be6a94 1 parent 00a2f13
@kriszyp kriszyp authored
Showing with 7 additions and 16 deletions.
  1. +7 −16 lib/jsgi-node.js
View
23 lib/jsgi-node.js
@@ -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);
@@ -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 ]
}
@@ -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();
}
Please sign in to comment.
Something went wrong with that request. Please try again.