-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoiding to set the "Content-Length" header for GET requests (#1460)
* Avoiding to set the "Content-Length" header for GET requests * code formatting
- Loading branch information
1 parent
ed3e235
commit 804c35c
Showing
3 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -951,6 +951,7 @@ Request.prototype._end = function() { | |
let data = this._data; | ||
const { req } = this; | ||
const { method } = this; | ||
const methodsWithBody = ['PUT', 'POST', 'PATCH']; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
niftylettuce
Collaborator
|
||
|
||
this._setTimeouts(); | ||
|
||
|
@@ -970,7 +971,11 @@ Request.prototype._end = function() { | |
} | ||
|
||
// content-length | ||
if (data && !req.getHeader('Content-Length')) { | ||
if ( | ||
methodsWithBody.includes(method) && | ||
data && | ||
!req.getHeader('Content-Length') | ||
) { | ||
req.setHeader( | ||
'Content-Length', | ||
Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a bug here, you need to support
OPTIONS
having a body. Technically any other methods thanTRACE
can have a body as far as I can tell from https://stackoverflow.com/questions/16339198/which-http-methods-require-a-body. This is why the tests are failing, seetest/basic.js
: