Skip to content
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

Add back the typed representation of the Link header #67

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

pietroalbini
Copy link

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 the authorization module, as both of them have more than a single type representing the header.

The PR is intended to be reviewed commit-by-commit.

@seanmonstar
Copy link
Member

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 enums (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?

@pietroalbini
Copy link
Author

Sounds reasonable!

@pietroalbini
Copy link
Author

@seanmonstar implemented that, and also wrote a macro to generate the implementation of those two automatically.

@chinedufn
Copy link

chinedufn commented Oct 5, 2021

Hello, hello! Is anything blocking this from landing?

nevermind: #91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants