-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Custom HeaderName constants #174
Comments
I suspect when macros 2.0 are stable, we could provide a However, I'm not sure of a way to be able to add custom headers into the internal enum table. It's really meant for the most common of headers, but custom headers aren't slow just because they don't have an internal variant. |
A The #[macro_use] extern crate lazy_static;
extern crate http;
use http::header::{HeaderMap, HeaderName, HeaderValue};
lazy_static! {
static ref X_FOO: HeaderName = HeaderName::from_lowercase(b"x-foo").unwrap();
static ref BAR_VAL: HeaderValue = HeaderValue::from_bytes(b"bar").unwrap();
}
fn main() {
let mut hs = HeaderMap::new();
hs.append(&*X_FOO, BAR_VAL.clone());
// See https://stackoverflow.com/a/48115258 for explanation of `&*X_FOO`
} |
One could allow to merge a custom table with the default table, and provide the result in some form - I doubt it's feasible to add single headers with a |
Along those lines, one could also consider the option to limit the set of supported headers and define a policy what to do with unknown/unsupported ones - in a given application that just doesn't know about care about, or handle more than a given set of headers, being able to e.g. ignore all others without further allocations and other unnecessary work, might be beneficial. |
It actually looks like eventually, |
This is either a feature request or a documentation request. With a terse pointer I might at least be able to offer a PR for the latter.
In an application I have a bunch of custom headers to write, and I'd like these to share the same pre-checked and pre-allocated performance advantages as the const
HeaderName
s provided in the crate for the standard headers, for example ACCEPT.Is there any way to do this shy of using, for example, the lazy_static crate? With a quick look at the source, it looks like the
HeaderName
innards are private. If not, is the lazy_static solution considered adequate and desirable, or is there interest in the possibility of exposing some form of the macro mechanism used internally to statically generate the standard headers?Hyper has a header! macro, but I don't see any automatic conversion or representation as a
http::header::HeaderName
.There are cases where I also could statically declare
HeaderValue
s with similar advantage, butHeaderName
is more fundamental.The only potentially related existing issue I can find is #168.
The text was updated successfully, but these errors were encountered: