Closed yoshuawuyts closed 3 years ago
Can (&str, &str)
implement this Header
trait?
I ask because I think it's still the best way to solve the Surf .header(header)
issue.
@Fishrock123 good question; will have to try. I suspect there may actually be limits on what we can do because of how we're using generics.
Oh woah, the impl actually worked! Added a test for it too:
#[cfg(test)]
mod test {
use super::*;
#[test]
fn header_from_strings() {
let strings = ("Content-Length", "12");
assert_eq!(strings.header_name(), "Content-Length");
assert_eq!(strings.header_value(), "12");
}
}
It's been a while. Assuming this is good -- going to merge it.
Sorry. I think this should probably be able to deal with borrows if possible, see #336/#335
Closes #286
This PR implements the
Header
trait, creating a unified interface for the convention we had ofTypedHeader::{value, name, apply}
. This instead enables an interface of:Because
header_name
andheader_value
have to be implemented,apply_header
has 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
,value
andapply
methods in favor of keeping the trait only. This patch also explicitly chose to keep thevalue
method 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
TE
and inTransferEncoding
. These have been adjusted and now use the right header name.Prior work
This patch serves as an alternative to https://github.com/http-rs/http-types/pull/285, implementing the design I referenced in https://github.com/http-rs/http-types/pull/285#issuecomment-750891612.
Future directions
We should consider taking a look at the
headers
submodule in general. A few changes I think would be worthwhile:HeaderName
instead.Headers
toHeaderMap
, matching thehyperium/hyper
naming conventionToHeaderValues
from an associated iterator to be an instance ofHeaderValues
instead. The trait precedes the concrete type, and having a trait and a type with similar names be completely unrelated feels awkward.AsRef
andAsMut
implementations are provided.http_types::headers
crate-level docs with an explainer of the different types in the crate.