-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http: verify method is a string #10111
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
242c5c9
http: verify method is a string
lucamaraschi c711ac7
http: added @cjihrig feedbacks
lucamaraschi 29f78c1
http: renamed method for consistency
lucamaraschi 7774c3a
http: variables rearrangement
lucamaraschi 9561854
http: changed let to var
lucamaraschi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const expectedSuccesses = [undefined, null, 'GET', 'post']; | ||
let requestCount = 0; | ||
|
||
const server = http.createServer((req, res) => { | ||
requestCount++; | ||
res.end(); | ||
|
||
if (expectedSuccesses.length === requestCount) { | ||
server.close(); | ||
} | ||
}).listen(0, test); | ||
|
||
function test() { | ||
function fail(input) { | ||
assert.throws(() => { | ||
http.request({ method: input, path: '/' }, common.fail); | ||
}, /^TypeError: Method must be a string$/); | ||
} | ||
|
||
fail(-1); | ||
fail(1); | ||
fail(0); | ||
fail({}); | ||
fail(true); | ||
fail(false); | ||
fail([]); | ||
|
||
function ok(method) { | ||
http.request({ method: method, port: server.address().port }).end(); | ||
} | ||
|
||
expectedSuccesses.forEach((method) => { | ||
ok(method); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the best backwards compatibility (and to emulate the method value selection behavior below the
typeof
check), I think theundefined
/null
check should be removed and just test for truthiness:The reason being that
options.method
could be one of several non-truthy values, such as0
andfalse
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case if
options.method
is set to0
results in a falsy value which is going to default the method toGET
in the following check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mscdex that would not fix the
non-truthy
values, confusing the defaulting of0
values toGET
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's a difference between semver-ness. This change is definitely going to be semver-major as-is, but it could be semver-patch with the check I suggested. It's up to you.