-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
new internal isURL
check can result in http.request()
option fields being ignored
#46981
Comments
There is no right or wrong in this detection. Unfortunately, we need to check for the structure of the URL because we can't check using instanceof due to electron's use case. I don't think there is a good way of checking this. cc @aduh95 @nodejs/url |
I've opened #46989 to address this, let me know if that would work for you. |
@aduh95 Thanks! This looks good to me. It resolves the issue for me. I'll add a review on your PR, though I'm not a node core reviewer, so it's of limited value. |
PR-URL: #46989 Fixes: #46981 Reviewed-By: Yagiz Nizipli <[email protected]>
PR-URL: #46989 Fixes: #46981 Reviewed-By: Yagiz Nizipli <[email protected]>
PR-URL: #46989 Fixes: #46981 Reviewed-By: Yagiz Nizipli <[email protected]>
PR-URL: nodejs#46989 Fixes: nodejs#46981 Reviewed-By: Yagiz Nizipli <[email protected]>
PR-URL: nodejs#46989 Fixes: nodejs#46981 Reviewed-By: Yagiz Nizipli <[email protected]>
PR-URL: nodejs#46989 Fixes: nodejs#46981 Reviewed-By: Yagiz Nizipli <[email protected]>
PR-URL: #46989 Fixes: #46981 Reviewed-By: Yagiz Nizipli <[email protected]>
PR-URL: nodejs#46989 Fixes: nodejs#46981 Reviewed-By: Yagiz Nizipli <[email protected]>
PR-URL: nodejs#46989 Fixes: nodejs#46981 Reviewed-By: Yagiz Nizipli <[email protected]>
PR-URL: nodejs#46989 Fixes: nodejs#46981 Reviewed-By: Yagiz Nizipli <[email protected]>
PR-URL: #46989 Backport-PR-URL: #48345 Fixes: #46981 Reviewed-By: Yagiz Nizipli <[email protected]>
Version
v20.0.0-nightly2023030448f99e5f6a
Platform
macOS, but will happen on any platform.
Subsystem
http, url
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Everytime a non-URL object is passed as first argument to
http.request()
with thehref
andorigin
fields (accidentally), and with other non-URL-y valid input arguments.What is the expected behavior?
That the "Foo" header is sent to the server.
What do you see instead?
When we run that, notice that the
Foo
header is not received by the HTTP server:With the preceding nightly node v20 build, the
Foo
header is received:Additional information
#46904 introduced a change to the internal
isURL
check that is used inhttp.request()
to determine if the first argument is a URL instance:node/lib/_http_client.js
Line 136 in db81af6
It now considers the first argument to be a URL if it has the
href
andorigin
fields.This resulted in a surprise for me.
Basically, the
@elastic/elasticsearch
module is building an options object forhttp.request(options, ...)
that includes thehref
andorigin
fields. (There isn't a good reason for it to include those fields other than -- I'm guessing -- the original change just having used all the fields on a WHATWG URL object, rather than reading the input arguments specified in the node docs).The result is that other non-URL-y fields in the
options
object are ignored, likeagent
andheaders
(and perhapsmethod
).I don't know if this would be considered a bug, but I'm opening it for discussion here. There isn't a good reason for the code above to be passing the
href
andorigin
fields to thehttp.request(...)
options. However, perhaps using just those two fields as theisURL
check forhttp.request
is too quick of a decision. Would it be too complex/slow to see if the giveninput
toClientRequest
includes any of the other legitimate options? I don't object to closing this issue if it is expected that accidentally passing in an input object withhref
andorigin
will be rare.The text was updated successfully, but these errors were encountered: