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
Fix net module to accept non-string header values #9062
Conversation
@@ -255,7 +255,7 @@ class ClientRequest extends EventEmitter { | |||
|
|||
const key = name.toLowerCase() | |||
this.extraHeaders[key] = value | |||
this.urlRequest.setExtraHeader(name, value) | |||
this.urlRequest.setExtraHeader(name, value.toString()) |
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.
Looking at line 249, we only check against undefined, which means null
could get through to here and the error would be a bit confusing, maybe the value === undefined
check could be updated to value == null
since that is the check we typically use in lots of places. What do you think?
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.
👍
spec/api-net-spec.js
Outdated
response.end() | ||
break | ||
default: | ||
assert(false) |
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.
Maybe an assert.equal(request.url, requestUrl)
before here would be better so when this fails we know what request.url
was.
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.
👍
spec/api-net-spec.js
Outdated
const statusCode = response.statusCode | ||
assert.equal(statusCode, 200) | ||
response.pause() | ||
response.on('data', function (chunk) { |
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.
Is this needed? Looks like it isn't using the data.
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.
👍
spec/api-net-spec.js
Outdated
@@ -364,6 +364,51 @@ describe('net module', function () { | |||
urlRequest.end() | |||
}) | |||
|
|||
it('should be able to set a non-string object as header value', function (done) { |
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.
as header...
-> as a header...
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.
👍
319689d
to
f3248e8
Compare
Maybe we should update the docs as well to broaden the https://electron.atom.io/docs/api/client-request/#requestsetheadername-value |
This is required to be compatible with node.js http module.
f3248e8
to
b3cf00a
Compare
Done |
Thanks for updating this 👍 ⚡️ |
This is required to be compatible with node.js http module.
For the record, I found this issue when trying to make the request module to work with electron's
net
module.