Rant: dealing with http::Uri is annoying as heck

107 points DebuggingPanda 27 comments

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.

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.