Improve support for typed HTTP headers #1829
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1826
This has two changes to improve support for typed HTTP headers:
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 tostd::convert::Infallible
(which will eventually be an alias for thenever
type!
).FromHeaders
trait, which allows for reading a type out of a set of HTTP headers. It's fallible and allows for returningNone
if the headers are simply not present. There are now two more methods onHeaders
:get
andget_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 implementsAsHeaders
) and switched Cosmos'PartitionKey
to implementAsHeaders
now that there's a way to return an error.