Skip to content
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

Merged
merged 1 commit into from Mar 30, 2017

Conversation

tarruda
Copy link
Contributor

@tarruda tarruda commented Mar 30, 2017

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.

@@ -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())
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

response.end()
break
default:
assert(false)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const statusCode = response.statusCode
assert.equal(statusCode, 200)
response.pause()
response.on('data', function (chunk) {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -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) {
Copy link
Contributor

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...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tarruda tarruda force-pushed the stringify-headers-in-net-module branch from 319689d to f3248e8 Compare March 30, 2017 18:07
@kevinsawicki
Copy link
Contributor

Maybe we should update the docs as well to broaden the value type?

https://electron.atom.io/docs/api/client-request/#requestsetheadername-value

This is required to be compatible with node.js http module.
@tarruda tarruda force-pushed the stringify-headers-in-net-module branch from f3248e8 to b3cf00a Compare March 30, 2017 19:02
@tarruda
Copy link
Contributor Author

tarruda commented Mar 30, 2017

Maybe we should update the docs as well to broaden the value type?

Done

@kevinsawicki kevinsawicki merged commit f805bbe into master Mar 30, 2017
@kevinsawicki kevinsawicki deleted the stringify-headers-in-net-module branch March 30, 2017 19:35
@kevinsawicki
Copy link
Contributor

Thanks for updating this 👍 ⚡️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants