Skip to content

Commit 1db98ea

Browse files
committed
If there's a body, add a content-length header.
1 parent c3a2712 commit 1db98ea

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/connection.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,21 @@ extend(Connection.prototype, {
5353
var body = opts.body;
5454
var headers = {'content-type': 'text/plain'};
5555

56-
if (body && typeof body === 'object') {
57-
if (opts.ld) {
58-
body = body.map(function (obj) {
59-
return JSON.stringify(obj);
60-
}).join('\r\n') + '\r\n';
61-
headers['content-type'] = 'application/x-ldjson';
56+
if (body) {
57+
if (typeof body === 'object') {
58+
if (opts.ld) {
59+
body = body.map(function (obj) {
60+
return JSON.stringify(obj);
61+
}).join('\r\n') + '\r\n';
62+
headers['content-type'] = 'application/x-ldjson';
63+
} else {
64+
body = JSON.stringify(body);
65+
headers['content-type'] = 'application/json';
66+
}
6267
} else {
63-
body = JSON.stringify(body);
64-
headers['content-type'] = 'application/json';
68+
body = String(body);
6569
}
70+
headers['content-length'] = body.length;
6671
}
6772

6873
this._request({

0 commit comments

Comments
 (0)