http icon indicating copy to clipboard operation
http copied to clipboard

URI: how to distinguish from invalid port vs no port number

Open niklasad1 opened this issue 4 years ago • 3 comments

Hey,

I read that default port was rejected in https://github.com/hyperium/http/issues/11.

However, the current API has pub fn port(&self) -> Option<Port<&str>> but it's not possible to distinguish when invalid port number vs when no port number. . Example:

let uri: Uri = "/hello/world".parse().unwrap();
assert!(uri.port().is_none());

let uri: Uri = "/hello/world:-9933".parse().unwrap();
assert!(uri.port().is_none());

Opinions about having pub fn port(&self) -> Result<Option<Port<&str>, Error> or something similar?

niklasad1 avatar Nov 04 '21 09:11 niklasad1

What is the rationale for not returning an error on invalid port numbers?

kaimast avatar Aug 03 '25 22:08 kaimast

It probably should return an error when the Uri/Authority itself is parsed, not when calling the accessor.

seanmonstar avatar Aug 03 '25 22:08 seanmonstar

It probably should return an error when the Uri/Authority itself is parsed, not when calling the accessor.

That is what I meant

kaimast avatar Aug 06 '25 14:08 kaimast