-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
lib: parse the incoming http message url with the whatwg url class #51498
base: main
Are you sure you want to change the base?
lib: parse the incoming http message url with the whatwg url class #51498
Conversation
Review requested:
|
lib/_http_server.js
Outdated
@@ -1030,6 +1035,11 @@ function parserOnIncoming(server, socket, state, req, keepAlive) { | |||
if (req.upgrade) | |||
return 2; | |||
} | |||
if(server.parseIncomingUrlWithWhatWg) { | |||
req.originalUrl = req.url; | |||
const newUrl = new URL(req.url, 'http://localhost'); |
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.
Wouldn't using the request host header be better than using localhost?
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.
True, but it depends on if we should expose the whole url instance
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.
+1 here, let's rebuild the original URL using the scheme and the host.
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.
+1 here, let's rebuild the original URL using the scheme and the host.
This will:
Moreover, a user can always do it themselves, and both Fastify and Express offer ways to specify custom http servers and intercept the request prior to routing. As a result, I'm not convinced this is useful. |
Hi @mcollina
Yes thats true, as currently no parsing is done.
Also true, but I think there are already compatibility issues, as the
Hmm yes, but I think it is really is useful when a framework behaves consistent. BR Stefan |
I believe |
I guess most Node.Js starters think that message.url is the full url and not only the path + query.
And I also guess that most of the experienced Node.Js developer don't know that |
I cannot comment on what those groups may or may not think. I was just trying to answer the "Why the url property does not follow the URL rules by the URL class?" |
lib/_http_server.js
Outdated
@@ -445,6 +445,11 @@ function storeHTTPOptions(options) { | |||
validateInteger(maxHeaderSize, 'maxHeaderSize', 0); | |||
this.maxHeaderSize = maxHeaderSize; | |||
|
|||
const parseIncomingUrlWithWhatWg = options.parseIncomingUrlWithWhatWg; |
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.
This option name needs to be definitely shorter. :)
lib/_http_server.js
Outdated
@@ -1030,6 +1035,11 @@ function parserOnIncoming(server, socket, state, req, keepAlive) { | |||
if (req.upgrade) | |||
return 2; | |||
} | |||
if(server.parseIncomingUrlWithWhatWg) { | |||
req.originalUrl = req.url; | |||
const newUrl = new URL(req.url, 'http://localhost'); |
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.
+1 here, let's rebuild the original URL using the scheme and the host.
lib/_http_server.js
Outdated
@@ -1030,6 +1035,11 @@ function parserOnIncoming(server, socket, state, req, keepAlive) { | |||
if (req.upgrade) | |||
return 2; | |||
} | |||
if(server.parseIncomingUrlWithWhatWg) { | |||
req.originalUrl = req.url; | |||
const newUrl = new URL(req.url, 'http://localhost'); |
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.
+1 here, let's rebuild the original URL using the scheme and the host.
I agree with @mcollina and @dougwilson. This will slow down things and maybe be confusing for the user. To clarify the last sentence, while your example for |
It looks fine to me now. |
I'm not sure it's fine to provide a builtin getter that can throw an error on invalid incoming messages. It may even become a security risk. |
I get it's not ideal to have a getter that might throw. |
It would be easy for the delevoper to trust the URL returned without thinking about the fact it is entirely built from user-provided input. For example, the |
Thanks for all the responses and the input I am not sure if the URL getter really helps for solving the original issue, that ../ and ./ is not evaluated for incoming requests.
Hmm, as far as I know there is no other way to resolve the host. |
Good point. We have to make this very clear in the docs. |
Draft for #51311
TODO:
originalUrl
orrawUrl