http core module issueΒ #9069
Copy link
Copy link
Closed
Labels
good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.httpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.questionIssues asking questions about Node.js.Issues asking questions about Node.js.
Description
on Node.js 6.7
I got this while using require('http').request()
[accounts.api.test.js] stack: TypeError: self.agent.addRequest is not a function
[accounts.api.test.js] at new ClientRequest (_http_client.js:158:16)
[accounts.api.test.js] at Object.exports.request (http.js:31:10)
[accounts.api.test.js] at Object.makeHTTPRequest [as httpHelper] (/Users/t_millal/WebstormProjects/autodesk/crucible-poc-discovery/test/helpers/http-helper.js:22:20)
[accounts.api.test.js] at TestSuiteBase.it.cb.t (/Users/t_millal/WebstormProjects/autodesk/crucible-poc-discovery/test/test-src/accounts.api.test.js:27:17)
[accounts.api.test.js] at /Users/t_millal/WebstormProjects/oresoftware/suman/lib/test-suite-helpers/handle-test.js:191:37
[accounts.api.test.js] at _combinedTickCallback (internal/process/next_tick.js:67:7)
[accounts.api.test.js] at process._tickDomainCallback (internal/process/next_tick.js:122:9)
probably shouldn't be happening no matter what the input data is, but here it is:
[accounts.api.test.js] => request d =>
[accounts.api.test.js] { host: 'localhost',
[accounts.api.test.js] port: 3001,
[accounts.api.test.js] path: '/api/Accounts',
[accounts.api.test.js] method: 'GET',
[accounts.api.test.js] agent: true, <<< seems to be culprit
[accounts.api.test.js] headers: { 'Content-Type': 'application/json' } }
curious as to what might be happening thanks, setting agent to false, will prevent this error being thrown...
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.httpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.questionIssues asking questions about Node.js.Issues asking questions about Node.js.
Activity
mscdex commentedon Oct 13, 2016
The
httpdocumentation shows valid values for theagentproperty.trueis not one of them.ORESoftware commentedon Oct 13, 2016
well shoot, maybe http should throw a better error when you pass an unacceptable value as an option..right?
not-an-aardvark commentedon Oct 15, 2016
If it accepts
false, it seems like it should also accepttruefor consistency (which would be equivalent to not providing the parameter).ORESoftware commentedon Oct 15, 2016
right, this is a little weird tbh
ORESoftware commentedon Oct 15, 2016
instead of false, it should accept null or undefined perhaps
bnoordhuis commentedon Oct 21, 2016
I've added the 'good first contribution' label but if no one picks it up within the next few weeks I'll go ahead and close it out as 'working as documented.'
the1mills commentedon Oct 24, 2016
Ok so more definitely, here are the current docs on this:
https://nodejs.org/api/http.html#http_http_request_options_callback
it says:
Let's talk about the above, but as an aside, let's say we did allow
agent:true, couldn't the HTTP core module deliver some "default" HTTP agent? or does it really have to be a user defined agent?seems like you could do this:
=> http.request options =>
so my thinking is here are the options:
So I think passing
nullshould throw an error (if it doesn't already). And eithertrueshould throw an error (it doesn't now) or true/'default' should create some default new HTTP.Agent. Right now the situation is not acceptable IMO.https://nodejs.org/api/http.html#http_new_agent_options
not-an-aardvark commentedon Oct 24, 2016
@the1mills, thanks for putting your thoughts into this. I have a few comments on your suggested options:
I'm not sure I agree with this. I don't think we should distinguish between
nullandundefinedas inputs, as that will lead to confusion. This would also be a breaking change, which I think is unnecessary in this case.I'm not sure I understand the point of having an explicit option for
'default'. If someone explicitly wants to use the default behavior, they can simply omit the property and have the default behavior take effect.In my opinion, the best course of action would be to simply allow
agent: trueto mean "yes, use an agent". This would nicely contrast with the existingagent: falseoption (which means "no agent"), and it also happens to be the same as the default behavior, which is to use an agent ifagentisundefined.sam-github commentedon Oct 24, 2016
I think it just makes things more weird. Having undefined (which is falsy) and false mean different things is odd, its not what someone would expect without reading the docs.
I would expect null to be falsy, and be the same as undefined or false... but that can't work: falsy like undefined, or falsy like false? Hm... I don't think there is anything we can do here that would be expected, the best thing would be to throw clear errors on any use of an invalid argument value, and expect people to read the docs.
not-an-aardvark commentedon Oct 24, 2016
I think
agent: falsesemantically means "don't use an agent".agent: truesemantically means "use an agent". Explicitly listingagent: undefineddoes seem sort of weird, and I'm not sure what it should mean, but a more common case would be omitting theagentproperty entirely, which triggers the default behavior.We could use
hasOwnPropertyto detect whetheragent: undefinedis explicitly passed, but I think changing the behavior based onhasOwnPropertywill be confusing. Similarly, I think treatingnullany differently thanundefinedwill be confusing.I don't think the API that I proposed above is overly confusing; if we allow
agent: true, then the option is basically a boolean value that defaults totrue. (This ignores the ability to pass a different agent instead of a boolean, but I think that can be considered separately.)sam-github commentedon Oct 25, 2016
Well, just my opinion here, but I still think this is rearranging the deck chairs on the titanic. It isn't going to make sense when undefined and false are defined to mean the opposite of each other.
The sensible api would be:
no agent property: do not use an agentagent: an agent object, use the agentagent: http.defaultAgent, use the default agentagent: true,false: not agents, throw erroragent: undefined: like no agent property, do not use an agentagent: null: like no agent property, do not use an agentbut that's very semver major :-)
And back to the main point. @the1mills got thrown off because of a terrible error message when they used the API in a way that was plainly documented to be wrong - just a decent error message would have avoided all this, and caused the OP to check the docs.
Fixing that is a good first contribution!
ORESoftware commentedon Oct 25, 2016
right I was saying agent:undefined is the same as
!options.hasOwnProperty('agent'),
should result in same thing
as for agent:true, it needs to be one of three things:
~agent:false, (would not make sense at all)
~agent:undefined,
or some 3rd thing
my vote is that agent:true procures some default agent of some variety
On Oct 24, 2016 1:58 PM, "Teddy Katz" notifications@github.com wrote:
1 remaining item
http: throw an error for unexpected agent values
http: throw an error for unexpected agent values
lance commentedon Jan 19, 2017
I think the semver-major recommendation from @sam-github makes sense. But yeah... it's semver-major. In any case, it seems that this issue has been resolved with #10053 so I'm going to close this.
Please feel free to reopen if I am mistaken.