-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Ergonomics of custom headers (header macro) #11
Comments
I went for raw_headers as opposed to the typed headers in an app which uses reqwest for now, I'd be up for implementing this if someone could guide me in the correct direction (Is a copy-paste of the header macro the best solution?). |
This is how I used header! macro with reqwest
It still would be nice, that reqwest reexported header! macro, as it is the only thing, why I directly have to depend on hyper. |
I know! But |
Could we as a stopgap measure til the feature becomes stable, re-implement the macro in the reqwest library? |
That's a possibility. I wonder if it makes sense to copy verbatim, of if this is an opportunity to make the macro less confusing. Perhaps keywords in the macro instead of sigils would make things more clear? header! {
name = "X-Foo";
type = Foo;
repr = [String]; // I don't know if Vec<String> would work, but if it would, maybe that's better?
} |
I like the key-value style of your suggestion, Alternatives quickly get verbose, f.ex with header! {
rust_name = Foo;
serialized_name = "X-Foo";
repr = [String];
} |
I think serialized name is still a bit foreign. I'd prefer calling it something like http_header_name. header! {
rust_name = Foo;
http_header_name = "X-Foo";
repr = [String];
} |
are there any examples for how to get a header? reqwest's header map takes a value argument and hypers takes a type argument. |
@softprops assuming you're asking about current reqwest (0.8.x), you can make use of type inference, or use turbofish syntax: let ty: ContentType = res.headers().get().unwrap();
let len = res.headers().get::<ContentLength>().unwrap; |
Sry I was mistaken. I was actually using the http crate which I thought reqwest used. |
Could you switch to the The macros are enormous hassle. I also don't see how such type-strict solution could work with header names only known at run time (e.g. |
The upcoming 0.9 release upgrades to hyper 0.12, which adds support for the |
@seanmonstar when doing it, are you also keeping support for the I ended doing a hackish solution for now, when upgrading to 0.9 release, but it is far from neat... :-( |
…-dsn Add constructor for SentryCredential from DSN
reqwest no longer has typed headers built in (could conceivably come back some day). |
It might be nice to duplicate hyper's
header!
macro for sending custom headers - for lack of macro_reexport. I moved an API client from hyper to reqwest, and custom headers is now the only reason I directly depend on hyper. Alternatively, splitting out headers (a la hyperium/hyper#894) into hyper-headers or hyper-types also seems like a reasonable way to get the extra macro.The text was updated successfully, but these errors were encountered: