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

Headers case #402

Closed
anton-dutov opened this issue Dec 18, 2018 · 19 comments
Closed

Headers case #402

anton-dutov opened this issue Dec 18, 2018 · 19 comments

Comments

@anton-dutov
Copy link

Some dummy servers requires uppercased headers (e.g. CLIENT-ID), but reqwest always sends as lowercased, any solution?

@seanmonstar
Copy link
Owner

In this case, the only solution is to fix the servers to follow the HTTP spec that headers are case-insensitive.

@antoinecarton
Copy link
Contributor

antoinecarton commented Feb 25, 2019

Hello,

I assume that it is possible to use the option implemented in hyper with http1_title_case_headers as defined here.

If we could introduce this field in the reqwest client builder (in async_impl/client.rs) that is in charge of setting up the hyper client, we could propagate this field to hyper that is already in charge of it.

Maybe something like this:

if config.http1_title_case_headers {
   builder.http1_title_case_headers(true);
}
let hyper_client = builder.build(connector);

I could do a PR for this.

WDYT?

EDIT: After a few tests with this field, it is possible to send case sensitive headers.

@antoinecarton
Copy link
Contributor

Hello,

This has been merged here: #463

@thepixelmonk
Copy link

is this PR compatible with reqwest at all or do I have to start using hyper?

@seanmonstar
Copy link
Owner

@toovs I'm sorry, what do you mean? This added the following option: https://docs.rs/reqwest/0.9.*/reqwest/struct.ClientBuilder.html#method.http1_title_case_headers

@thepixelmonk
Copy link

thanks for the link, I was reading an older version of the docs for some reason.

@thepixelmonk
Copy link

I'm still getting a panic when using capitalization with HeaderName::from_static(), what method should I be using instead?

@seanmonstar
Copy link
Owner

from_static requires a lowercase name, but that ClientBuilder option will serialize the name in Title-Case to the socket.

@thepixelmonk
Copy link

I'm trying to interface with twitch.tv's api and I need to send the "Client-ID" header, so I guess it's incorrectly sending "Client-Id" if it's automatically converting to Title-Case?

@seanmonstar
Copy link
Owner

Yes, title-case would serialize as Client-Id. I'm very surprised Twitch doesn't use a headers collection that is case-insensitive. I'd suggest file a bug on the API. Looks like there's an alternative to send the client ID in a query parameter, though.

@thepixelmonk
Copy link

ah yes a query param would work, thx for the suggestion.

@ghost
Copy link

ghost commented Sep 10, 2020

Sorry to resurrect an old issue, but I think this behaviour might be unnecessarily opinionated in two ways:

  1. If it's the serialisation to the socket which has the final say on header name case, why not allow any case in HeaderName::from_static() etc, with the case then being converted as necessary? A panic feels too harsh.

  2. Since (as demonstrated from the above conversation) there exist servers in the world which require the wrong case in header names, can't there be a ClientBuilder option, or a way of passing specific headers, which just keeps whatever case you give it? Yes, you'll be breaking the http spec, but clearly some services require that you do so.

Just some suggestions :)

@rcastill
Copy link

rcastill commented Oct 28, 2020

Totally agree with @johnmarkwayve. In theory, yes, all http servers should be http compliant, but in practice, it is not the case. I use reqwest in real (practical) scenarios. Besides, if http defines headers to be case-insensitive, then why not just keep the header keys exactly as the user provides them? it would do no harm and the control would be up to the user.

@midshell-ghoul
Copy link

I'm dealing with the exact same situation, unable to use reqwest properly due to a server that doesn't follow the HTTP spec, and the server API isn't going to change.

@seanmonstar I'd love to see HeaderName use the case provided to it, or have a variable for this. As @rcastill said above, I don't see harm providing this control to the user.

@chemicstry
Copy link

I'm also experiencing this issue with bad server implementations and this forces me to use some alternative library, when I would rather use the same one (reqwest) for everything. There are cases where you just can't fix the http server (binary firmware).

@benoist
Copy link

benoist commented Sep 8, 2021

Hi, I'm dealing with this issue as well.

We are dealing with many different servers and we cannot possible force them to change to case insensitive headers.
For example Coinbase is forcing us to define CB-ACCESS-KEY which is something I currently can't do.

@joshzeldin
Copy link

@benoist Did you find a workaround for this? I'm hitting the same issue.

@kulame
Copy link

kulame commented Aug 15, 2022

Is there any progress now? I have this problem too

@bnheise
Copy link

bnheise commented Mar 6, 2023

Having this problem too. Can we please just let the user send whatever they want? If the spec says "case insensitive" then by requiring everything to be lowercase, you yourself are violating the spec.

Repository owner locked as resolved and limited conversation to collaborators Mar 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests