Skip to content

Commit 3d482a6

Browse files
committed
Set content-length: 0 on POST with empty data to support dumb servers
1 parent baeda7e commit 3d482a6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/XMLHttpRequest.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,18 @@ exports.XMLHttpRequest = function() {
327327
}
328328

329329
// Set content length header
330-
if (settings.method == "GET" || settings.method == "HEAD") {
330+
if (settings.method === "GET" || settings.method === "HEAD") {
331331
data = null;
332332
} else if (data) {
333333
headers["Content-Length"] = Buffer.byteLength(data);
334334

335335
if (!headers["Content-Type"]) {
336336
headers["Content-Type"] = "text/plain;charset=UTF-8";
337337
}
338+
} else if (settings.method === "POST") {
339+
// For a post with no data set Content-Length: 0.
340+
// This is required by buggy servers that don't meet the specs.
341+
headers["Content-Length"] = 0;
338342
}
339343

340344
var options = {

0 commit comments

Comments
 (0)