Rant: dealing with http::Uri is annoying as heck
I need to vent a bit, as I again ran into a situation where I am getting increasingly frustrated by dealing with an http::Uri.
I am building an HTTP server application, so the http crate is in my dependency tree and its Uri type is exposed in various places (e.g. hyper). Oftentimes, I need to inspect or manipulate URIs. For example, my application can be configured and many config values are URI-like. But: most have some limitations that I want to check for, e.g. "only http or https scheme + authority; no path, query or fragment". Doing these checks, or generally inspecting or manipulating this type is quite annoying though.
http://localhost.parse().path_and_query() == Some("/")(and.path() == "/")- The fragment part (
#foo) just gets dropped while parsing Uriis immutable -> modifying an URI by just replacing one part, for example, is needlessly involved. Especially becausePartshas private fields (i.e. cannot be created with struct init syntax) and bunches together things one might want to separate. ref1 ref2- No methods to return username or password from the authority. ref
- No neat helper methods like
uri.has_http_like_scheme() - ... and many, many more issues
And I hear you: "Just use the url crate!". I think this post should explain my concerns with it. Even ignoring the dependency problem or the fact that it would compile two separate URL parsers into my binary: when using hyper, I have Uris everywhere, so converting them back and forth is just annoying, especially since there is no convenient way to do that!
It is just plain frustrating. I have been in this situation countless times before! And every time I waste lots of time wrangling confusing APIs, writing lots of manual boilerplate code, having an existential breakdown, and considering whether to cargo add url. I can only imagine the accumulated human life wasted due to this :(
As a disclaimer I should say that all these issues are known to the maintainers and there are some valid arguments for why things are the way they are. I still think the current situation is just not acceptable for the whole ecosystem and it should be possible somehow to fix this.
Thanks for coming to my TED talk.