Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

url: treat empty port as default #483

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ethomson
Copy link

When parsing URLs, treat an empty port (eg http://hostname:/) as if it were unspecified. RFC 3986 says:

URI producers and normalizers SHOULD omit the port component and its ":" delimiter if port is empty or if its value would be the same as that of the scheme's default.

(Emphasis mine.) This indicates that URIs MAY be produced with an empty port and the : delimiter.

Thus, we stop failing if we end host parsing at the port delimiter.

When parsing URLs, treat an empty port (eg `http://hostname:/`) as if it
were unspecified.  RFC 3986 says:

> URI producers and normalizers SHOULD omit the port component and its
> ":" delimiter if port is empty or if its value would be the same as
> that of the scheme's default.

(Emphasis on the "SHOULD" is mine.)  This indicates that URIs MAY be
produced with an empty port and the `:` delimiter.

Thus, we stop failing if we end host parsing at the port delimiter.
@indutny
Copy link
Member

indutny commented Jun 26, 2019

cc @nodejs/http : are we aware of any possible side effects that might happen in Node.js after landing this?

@indutny
Copy link
Member

indutny commented Jun 26, 2019

@ethomson thank you for an excellent PR! The change looks great. It has to be considered in the context of Node.js too, however. Let's wait for @nodejs/http to get better understanding of interactions of this PR and Node core.

@indutny
Copy link
Member

indutny commented Jun 26, 2019

As a side note, I wonder if libgit2 might be interested in using llhttp instead of http_parser? The former is faster and verifiable, and is already used in the latest Node.js.

@ethomson
Copy link
Author

ethomson commented Dec 8, 2019

Interesting...! Thanks for the pointer @indutny. I’ll take a look, particularly since I’m interested in pausing in my on_headers_complete callback. Would you happen to know offhand if llhttp fixes #97 or if that’s still an issue?

@mgorny
Copy link

mgorny commented Feb 21, 2020

@nodejs/http, ping.

@sam-github
Copy link
Contributor

@nodejs/http

@@ -2326,7 +2326,6 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
case s_http_host_v6:
case s_http_host_v6_zone_start:
case s_http_host_v6_zone:
case s_http_host_port_start:
Copy link
Member

Choose a reason for hiding this comment

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

This changes the behavior of http_parser_parse_url(is_connect=1) in that it'll now allow CONNECT hostname: as valid input, doesn't it?

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

Successfully merging this pull request may close these issues.

None yet

5 participants