|
@ -228,6 +228,8 @@ function OutgoingMessage (socket) { |
|
|
this.flushing = false; |
|
|
this.flushing = false; |
|
|
this.headWritten = false; |
|
|
this.headWritten = false; |
|
|
|
|
|
|
|
|
|
|
|
this._hasBody = true; |
|
|
|
|
|
|
|
|
this.finished = false; |
|
|
this.finished = false; |
|
|
} |
|
|
} |
|
|
sys.inherits(OutgoingMessage, events.EventEmitter); |
|
|
sys.inherits(OutgoingMessage, events.EventEmitter); |
|
@ -309,12 +311,16 @@ OutgoingMessage.prototype.sendHeaderLines = function (firstLine, headers) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (sentContentLengthHeader == false && sentTransferEncodingHeader == false) { |
|
|
if (sentContentLengthHeader == false && sentTransferEncodingHeader == false) { |
|
|
if (this.useChunkedEncodingByDefault) { |
|
|
if (this._hasBody) { |
|
|
messageHeader += "Transfer-Encoding: chunked\r\n"; |
|
|
if (this.useChunkedEncodingByDefault) { |
|
|
this.chunkedEncoding = true; |
|
|
messageHeader += "Transfer-Encoding: chunked\r\n"; |
|
|
} |
|
|
this.chunkedEncoding = true; |
|
|
else { |
|
|
} else { |
|
|
this.closeOnFinish = true; |
|
|
this.closeOnFinish = true; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// Make sure we don't end the 0\r\n\r\n at the end of the message.
|
|
|
|
|
|
this.chunkedEncoding = false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -337,6 +343,10 @@ OutgoingMessage.prototype.write = function (chunk, encoding) { |
|
|
throw new Error("writeHead() must be called before write()") |
|
|
throw new Error("writeHead() must be called before write()") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!this._hasBody) { |
|
|
|
|
|
throw new Error("This type of response MUST NOT have a body."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
encoding = encoding || "ascii"; |
|
|
encoding = encoding || "ascii"; |
|
|
if (this.chunkedEncoding) { |
|
|
if (this.chunkedEncoding) { |
|
|
if (typeof chunk == 'string') { |
|
|
if (typeof chunk == 'string') { |
|
@ -415,6 +425,18 @@ ServerResponse.prototype.writeHead = function (statusCode) { |
|
|
|
|
|
|
|
|
var statusLine = "HTTP/1.1 " + statusCode.toString() + " " |
|
|
var statusLine = "HTTP/1.1 " + statusCode.toString() + " " |
|
|
+ reasonPhrase + CRLF; |
|
|
+ reasonPhrase + CRLF; |
|
|
|
|
|
|
|
|
|
|
|
if (statusCode === 204 || statusCode === 304) { |
|
|
|
|
|
// RFC 2616, 10.2.5:
|
|
|
|
|
|
// The 204 response MUST NOT include a message-body, and thus is always
|
|
|
|
|
|
// terminated by the first empty line after the header fields.
|
|
|
|
|
|
// RFC 2616, 10.3.5:
|
|
|
|
|
|
// The 304 response MUST NOT contain a message-body, and thus is always
|
|
|
|
|
|
// terminated by the first empty line after the header fields.
|
|
|
|
|
|
this._hasBody = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.sendHeaderLines(statusLine, headers); |
|
|
this.sendHeaderLines(statusLine, headers); |
|
|
this.headWritten = true; |
|
|
this.headWritten = true; |
|
|
}; |
|
|
}; |
|
|