-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
(async) Remove or replace typed headers #1067
Comments
Typed headers exist at hyperium/headers, and they can be used with the latest releases of |
Thanks for pointing that out, I missed and/or forgot about it when I checked for existing implementations. |
It’s not well advertised, and it requires importing an extension trait so that the The derive headers in the repository only supports headers defined within |
I'm inclined towards trying out the headers from the |
This should be an easy issue to help with, and first it's a bit of a research question - how complete is I previously opened hyperium/headers#48 because the types I looked at (
Looking forward:
Any help would be appreciated in terms of Proof-of-Concept, feedback on what should be prioritized, or testimonials for any of the crates or approaches I've mentioned or not mentioned above. |
Can I take a swing at this issue? I will need to get familiar with hyperium along with the internals related to the change, but I have the time to commit for the foreseeable future. |
I was just looking at this: Ad 2) As for applicable type header libraries, it appears that both Both support:
But
However,
The support seems to be quite comparable, and the fact that Ad 1) It seems easier to identify the header library first, and then refine the header list afterwards. Ad 3) So, a proof-of-concept should handle how to to get or match the headers (i.e. how they bridge with As for matching with the request, I'm guessing there may be several ways of accessing headers: #[get("/")]
fn index(languages: AcceptLanguage) -> String {
// Only match this route if the "Accept-Language" header is included in the request
...
} or perhaps: #[get("/")]
fn index(languages_opt: Option<AcceptLanguage>) -> String {
// This route is always matched on GET /, but the "Accept-Language" may be omitted from the request
...
} I didn't see a reasonable handling for repeated headers in the three typed header libraries. From a request, repeated headers should "fold" their values together while preserving order, but only if they're of the repeating kind (like Accept-Language). Some types should never repeat, that would be a user error (like Host). Mabye it's best to defer that little bit. For responses, I assume the headers need to work with the responder derive macros, like ContentType is handled today. I'm assuming that it is acceptable to expose the imported typed headers (via aliases) as it's done for http::hyper. Right? Is that the rough scope for going forward? |
In other words, this issue affects rocket itself only a little bit since there are not too many headers being set by Rocket, but it affects applications using rocket in proportion to how frequently they used those headers.
This is #1283, and is a new feature rather than fixing a regression - but I am also interested in it. This would give us both
If it were entirely up to me to decide this and I had to choose today, I think I would pick
This is about what I had in mind, yeah: restoring the functionality that was lost is the main goal of this issue, even if we gain/lose a few individual headers in the process, change the way the functionality is accessed, or use a different library, as long as we are comfortable with it (and so far, I do like or at least don't mind |
Thanks, I'll see about It turns out that the API in I'm not a very seasoned Rust developer, but I'll give it a go! |
Happy to hear it! It's actually a fairly simple change in terms of lines of code; the main thing to look at is this part of |
An update on this one: It would appear that Be warned though, that I don't see a way to do this in an entirely zero copy fashion as previously discussed. Another API impedance mismatch is around multiple header values. The mechanisms in Responder and FromRequest only allow one value at a time, but some of the typed headers can encode or decode more than one value. It looks like this may not be an actual problem, since only the |
I have now pushed an implementation of (I have not further investigated the API richness of the headers crate as compared to the alternatives.) There seems to be a build issue on |
Typed headers were removed between hyper 0.10 and hyper 0.12.
typed-headers
does not appear to have all the headers hyper 0.10 did, but it looks likehyperx
andheaders
might.Options:
async
branch; only the header names are available in hyper and we re-export those.From<X> for Header
for every header in one or both ofhyperx
andtyped-headers
, perhaps behind a feature flagThe text was updated successfully, but these errors were encountered: