headers
headers copied to clipboard
Add back the typed representation of the Link header
After the extraction of this crate from the main hyper codebase, the Link
header was removed from the public API and moved into the disabled/
directory. Having a parser for that header is a feature I think is really needed, as its syntax is not exactly trivial.
This PR adds it back by moving the existing code from the disabled/
directory to common/
, and updating it to work with the current codebase and API. Most of the PR consists of a straight port of the existing code, but I made two changes of my own:
- A test that was previously commented was decommented (and then ported).
- Instead of re-exporting all items to the top module, I decided to export the whole
link
module. This mimics the behavior of theauthorization
module, as both of them have more than a single type representing the header.
The PR is intended to be reviewed commit-by-commit.
Thanks for the work in updating this code!
I had disabled some of the typed headers when I felt the public interface was either exposing too many internal details (thus preventing future optimizations or refactors), or that involved too many allocations or copies.
In the case of Link
, my first concern I think is various enum
s (MediaDesc
and RelationType
). I think using enum
for them may actually be the wrong choice (I've grown wary of public enums that have some Ext(String)
variant). For instance, if some extension eventually becomes standardized, then MediaDesc::Ext("foobar")
should become MediaDesc::FooBar
...
In these cases, perhaps the types should be struct MediaType(Inner)
, with the variants exposed as constants (like http::StatusCode
). What do you think of that?
Sounds reasonable!
@seanmonstar implemented that, and also wrote a macro to generate the implementation of those two automatically.
~Hello, hello! Is anything blocking this from landing?~
nevermind: https://github.com/hyperium/headers/pull/91