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

web::uri::port() vs web::uri::is_port_default() #1262

Open
garethsb-sony opened this issue Oct 17, 2019 · 0 comments
Open

web::uri::port() vs web::uri::is_port_default() #1262

garethsb-sony opened this issue Oct 17, 2019 · 0 comments

Comments

@garethsb-sony
Copy link
Contributor

@garethsb-sony garethsb-sony commented Oct 17, 2019

web::uri::port() says "Returns -1 if no port is specified."

This is the initial value of a default-constructed web::uri or web::uri_builder.

However, web::uri::is_port_default() tests for port() == 0.

Parsing a URI string e.g. using the web::uri constructor, results in the port being set to 0 if the URI string doesn't specify a port.

This means that:
web::uri(U("http://example.com/")) != web::uri_builder().set_scheme(U("http")).set_host(U("example.com")).to_uri()

That was surprising to me.

Are 'port unspecified' (-1) and 'port default' really supposed to be distinct?
In other words, should a user of web::uri_builder have to explicitly set default port?

web::uri(U("http://example.com/")) == web::uri_builder().set_scheme(U("http")).set_host(U("example.com")).set_port(0).to_uri()

If so, since the fact that 0 indicates default is not documented, would it be worth adding uri_builder::set_default_port()?

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

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.