-
Notifications
You must be signed in to change notification settings - Fork 347
Method to get port regardless of defaults #706
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
Comments
So, the parsing algorithm removes the port if it's equal to the default. Could you explain the need for such an interface? |
In my use case I'm building a library enabling a QUIC powered custom protocol implementation. The issue is that I don't want to handle standard protocols, the user has to be forced to supply a port, letting the user rely on default protocol ports is confusing on the input level and pretends like the library is protocol-aware, which it isn't. As an alternative I might want to disable any standard protocols the user might use, but QUIC is compatible with HTTP/3 in a way, and it would require me to filter protocols, which again, I don't want to do because this library shouldn't be protocol-aware. I know this is pretty niche. |
Could you instead do a check after parsing that the port was set in the input?
I know this is a hacky solution, but I'd rather not add maintenance burden for such a limited use case. |
That is the solution I'm using for now. But it has the problems I pointed at above, there will be some protocols which have default ports, and others which don't, which is confusing during setup for a library that isn't protocol aware. I do understand that this is a limited use-case, but I find it very useful for the Url crate to actually be able to parse URL's without any "interpretation" by RFC's and standards. Of course if this is something the Url crate doesn't consider to be in scope or not valuable, feel free to close this issue and my corresponding PR. |
I closed the PR for now, but I'll leave this open for now. Maybe we can find a way to accommodate this use case in the future. |
I need this for a different use case: I want to set a default port, unless the user specified a port in the input. Is there any workaround for this? |
This is the same use-case we need actually, you explained it way better though! |
This came up for us as well. We'd like to just retrieve the port if it is included in the URL, regardless of whether it is the default port for the scheme.
What would this actually look like though? It seems to me like we would need to parse the URL ourselves to figure out if a port was specified. EDIT I suppose we could just search for |
I checked URL parsing in other languages for the ability to distinguish between In my testing Go and Python allow that. If it's good or bad is a different story.
|
At the moment, when using the
port
method on an URL that uses a known scheme with none or the default port,port
will returnNone
.port_or_known_default
will always return the default port for known scheme's unless a non-default port is set in the URL.Currently there is no way to determine if the input string contained a port or not, for applications which do not want to support any default ports, regardless of scheme's, this is a current limitation.
I propose adding a method
port_int
(likehost_str
, bikeshedding is welcome) that returns whatever port is set in the URL string, regardless of defaults.The text was updated successfully, but these errors were encountered: