Skip to content

Commit

Permalink
Revert "Avoiding to set the "Content-Length" header for GET requests (#…
Browse files Browse the repository at this point in the history
…1460)" (#1477)

This reverts commit 804c35c.
  • Loading branch information
niftylettuce committed Apr 8, 2019
1 parent 804c35c commit fe8d902
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 33 deletions.
7 changes: 1 addition & 6 deletions src/node/index.js
Expand Up @@ -951,7 +951,6 @@ Request.prototype._end = function() {
let data = this._data;
const { req } = this;
const { method } = this;
const methodsWithBody = ['PUT', 'POST', 'PATCH'];

this._setTimeouts();

Expand All @@ -971,11 +970,7 @@ Request.prototype._end = function() {
}

// content-length
if (
methodsWithBody.includes(method) &&
data &&
!req.getHeader('Content-Length')
) {
if (data && !req.getHeader('Content-Length')) {
req.setHeader(
'Content-Length',
Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data)
Expand Down
15 changes: 0 additions & 15 deletions test/request.js
Expand Up @@ -172,21 +172,6 @@ describe('request', function() {
});
});

it('GET should not send the content-length header', next => {
request
.get(`${uri}/content-length`)
.send({ foo: 'bar' })
.then(res => {
try {
assert(!res.badRequest);
next();
} catch (err) {
next(err);
}
})
.catch(next);
});

it('get()', next => {
request.get(`${uri}/notfound`).end((err, res) => {
try {
Expand Down
12 changes: 0 additions & 12 deletions test/support/server.js
Expand Up @@ -578,17 +578,5 @@ app.get('/error/redirect-error:id', (req, res) => {
}
});

app.get('/content-length', (req, res) => {
const { headers } = req;
if (
headers.hasOwnProperty('content-length') &&
headers['content-length'] > 0
) {
res.status(400).send('bad request');
} else {
res.status(200).send('ok');
}
});

const server = http.createServer(app);
server.listen(process.env.ZUUL_PORT);

0 comments on commit fe8d902

Please sign in to comment.