From 887f05692353d01ec97e1e99ff34479a433ad985 Mon Sep 17 00:00:00 2001
From: Ryan
Date: Sat, 6 Jun 2009 23:57:15 +0200
Subject: [PATCH] Do not assume transfer-encoding: chunked as default on
requests.
If users do not send transfer-encoding or content-length headers, then I
will not add any additional. Content-Length: 0 is assumed if there aren't
other headers and chunked encoding is rare.
---
src/http.js | 9 +++++----
website/api.html | 6 ++++++
2 files changed, 11 insertions(+), 4 deletions(-)
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