Implement the Header trait
#315
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 #286
This PR implements the
Headertrait, creating a unified interface for the convention we had ofTypedHeader::{value, name, apply}. This instead enables an interface of:Because
header_nameandheader_valuehave to be implemented,apply_headerhas a default implementation. This should make it easier to keep up to date.Breaking changes
This patch doesn't break anything, but it does set us up for the 3.0.0 release. When we're ready to implement the 3.0.0 changes we should remove the
name,valueandapplymethods in favor of keeping the trait only. This patch also explicitly chose to keep thevaluemethod implementation where it is in order to not create a massive merge conflict with #313.Bug fixes
This patch also fixes two bugs: a wrong header name in
TEand inTransferEncoding. These have been adjusted and now use the right header name.Prior work
This patch serves as an alternative to #285, implementing the design I referenced in #285 (comment).
Future directions
We should consider taking a look at the
headerssubmodule in general. A few changes I think would be worthwhile:HeaderNameinstead.HeaderstoHeaderMap, matching thehyperium/hypernaming conventionToHeaderValuesfrom an associated iterator to be an instance ofHeaderValuesinstead. The trait precedes the concrete type, and having a trait and a type with similar names be completely unrelated feels awkward.AsRefandAsMutimplementations are provided.http_types::headerscrate-level docs with an explainer of the different types in the crate.