diff --git a/src/http.js b/src/http.js
index 6f878c06072..ee89eeddfea 100644
--- a/src/http.js
+++ b/src/http.js
@@ -359,16 +359,17 @@ node.http.Client = function (port, host) {
header += "Connection: keep-alive\r\n";
}
- if (sent_content_length_header == false && sent_transfer_encoding_header == false) {
- header += "Transfer-Encoding: chunked\r\n";
- chunked_encoding = true;
- }
header += CRLF;
var output = [];
send(output, header);
this.sendBody = function (chunk, encoding) {
+ if (sent_content_length_header == false && chunked_encoding == false) {
+ throw "Content-Length header (or Transfer-Encoding:chunked) not set";
+ return;
+ }
+
if (chunked_encoding) {
send(output, chunk.length.toString(16));
send(output, CRLF);
diff --git a/website/api.html b/website/api.html
index 7b7da4cd850..00a9a7904fa 100644
--- a/website/api.html
+++ b/website/api.html
@@ -750,6 +750,12 @@ req.finish(function (res) {
by Node. Returns a ClientRequest
object.
+ Do remember to include the Content-Length
header if you
+ plan on sending a body. If you plan on streaming the body, perhaps
+ set Transfer-Encoding: chunked
.
+
Important: the request is not complete. This method only sends the header of the request. One needs to call