Skip to content
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

How can I add custom header as in hyper? #134

Closed
iddm opened this issue Jun 1, 2017 · 6 comments
Closed

How can I add custom header as in hyper? #134

iddm opened this issue Jun 1, 2017 · 6 comments

Comments

@iddm
Copy link

iddm commented Jun 1, 2017

I am moving my crate to reqwest to try it. But I have one problem: in hyper I could easily create my own header:

header! {
    (XApiKey, "X-Api-Key") => [String]
}

But I don't know how can I do that with reqwest.

@little-dude
Copy link
Contributor

little-dude commented Jun 1, 2017

You can do the exact same thing. Use hyper to create your header. Here is an example:
https://docs.rs/reqwest/0.6.2/reqwest/header/index.html#defining-custom-headers

This works because reqwest::header is actually a re-export of hyper::header: https://github.com/seanmonstar/reqwest/blob/master/src/lib.rs#L150

@little-dude
Copy link
Contributor

@iddm
Copy link
Author

iddm commented Jun 2, 2017

@little-dude yes, that is how I did that. But, I must say: if reqwest is a hyper-wrapper, why do I need hyper? I mean, when I don't use any custom headers I simply may use only reqwest, but when I do, I must add hyper dependency to my crate, so my project has both hyper and reqwest depdendencies what I think is bad. Is there any way to re-export macro from hyper::header module to reqwest?

@little-dude
Copy link
Contributor

my project has both hyper and reqwest depdendencies what I think is bad

It's annoying but I don't think it's bad.

Is there any way to re-export macro from hyper::header module to reqwest?

Yes and no. Yes it's possible but this works by accident. This is also possible with a feature flag (#![feature(use_extern_macro)]), but that means it unstable. I'm not sure if @seanmonstar wants to use this or not.

@iddm
Copy link
Author

iddm commented Jun 2, 2017

As long as I must follow hyper version which is used in the reqwest crate (to avoid duplicates which would lead to downloading 2 different versions, compiling them, linking (which will also give openssl troubles and so on) just to easily create header - this is bad. It would be better to wrap hyper's macro with your own in reqwest and export it.

@seanmonstar
Copy link
Owner

This has come up before. See #11. In short, we either need macros 2.0, to allow importing the macro like any other symbol, or to define a new header! macro in reqwest. Comments in #11.

repi pushed a commit to EmbarkStudios/reqwest that referenced this issue Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants