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

Improve support for typed HTTP headers #1829

Merged
merged 5 commits into from
Oct 2, 2024

Conversation

analogrelay
Copy link
Member

Closes #1826

This has two changes to improve support for typed HTTP headers:

  1. The AsHeaders trait, used to convert a type into a set of HTTP headers, is now fallible. Types which can be infallibly converted to headers should set their error type to std::convert::Infallible (which will eventually be an alias for the never type !).
  2. Added a new FromHeaders trait, which allows for reading a type out of a set of HTTP headers. It's fallible and allows for returning None if the headers are simply not present. There are now two more methods on Headers: get and get_optional which allow for reading a required or optional value out of the headers.

I've put a few notes inline that I wanted to specifically call attention to. I also updated Range (the only "built-in" type that implements AsHeaders) and switched Cosmos' PartitionKey to implement AsHeaders now that there's a way to return an error.

Copy link
Member

@heaths heaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this! I see nothing blocking, but had a few suggestions.

@analogrelay analogrelay merged commit 048717f into feature/track2 Oct 2, 2024
43 checks passed
@analogrelay analogrelay deleted the ashleyst/asheaders-fromheaders branch October 2, 2024 20:35
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