This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Tell the user why the HTTP response should not have a body.

  • Loading branch information...
tylermwashburn
tylermwashburn committed Dec 3, 2011
1 parent 46b6954 commit 8944e282e3319a9848a359f39a7b8cedab8df7e1
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/http.js
View
@@ -592,7 +592,7 @@ OutgoingMessage.prototype.write = function(chunk, encoding) {
}
if (!this._hasBody) {
- console.error('This type of response MUST NOT have a body. ' +
+ console.error('This type of response (' + this._noBodyReason + ') MUST NOT have a body. ' +
'Ignoring write() calls.');
return true;
}
@@ -654,7 +654,7 @@ OutgoingMessage.prototype.end = function(data, encoding) {
}
if (data && !this._hasBody) {
- console.error('This type of response MUST NOT have a body. ' +
+ console.error('This type of response (' + this._noBodyReason + ') MUST NOT have a body. ' +
'Ignoring data passed to end().');
data = false;
}
@@ -773,7 +773,10 @@ OutgoingMessage.prototype._flush = function() {
function ServerResponse(req) {
OutgoingMessage.call(this);
- if (req.method === 'HEAD') this._hasBody = false;
+ if (req.method === 'HEAD') {
+ this._hasBody = false;
+ this._noBodyReason = "HEAD";
+ }
if (req.httpVersionMajor < 1 || req.httpVersionMinor < 1) {
this.useChunkedEncodingByDefault = false;
@@ -858,6 +861,7 @@ ServerResponse.prototype.writeHead = function(statusCode) {
// consisting only of the Status-Line and optional headers, and is
// terminated by an empty line.
this._hasBody = false;
+ this._noBodyReason = statusCode;
}
// don't keep alive connections where the client expects 100 Continue

0 comments on commit 8944e28

Please sign in to comment.