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

User-Agent should be properly capitalized in exec #4034

Conversation

dylandrop
Copy link
Contributor

As per the HTTP spec, User-Agent is supposed to be capitalized per-word. Today, the Agent part is simply missing a capital A in the defaults set by exec.

require "http"
client = HTTP::Client.new "www.google.com"
req = HTTP::Request.new("GET", "/")
response = client.exec req
puts req.headers #=> HTTP::Headers{"User-agent" => "Crystal", "Accept-Encoding" => "gzip, deflate"}

@asterite
Copy link
Member

Hi,

Thanks for this, but do you have a bug related to this? The RFC says http headers are case insensitive.

@Sija
Copy link
Contributor

Sija commented Feb 15, 2017

@asterite some web/app servers are not fully rfc compliant so this might help to overcome their faulty implementation. Also, that's a good rule of a thumb to keep this capitalized (rfc you mentioned uses User-Agent casing btw).

@asterite
Copy link
Member

But then the change is not here, it's in how HTTP::Headers present these headers to the outside. Right now it presents them as the value that was put in them.

Also, it would help to know which server is not RFC compliant so that we can test against that. So far I never had trouble with HTTP::Client setting that header...

@spalladino
Copy link
Contributor

There's even an npm package for using that casing it seems (I know, there's an npm package for pretty much everything, but let's put that aside for now).

I agree that this change should be made on how headers are sent, but still, I see no harm in merging this PR.

@asterite asterite merged commit ee3baad into crystal-lang:master Feb 15, 2017
@ysbaddaden
Copy link
Contributor

Just to chime in, HTTL headers are now all lowercase in HTTP/2. E.g., user-agent.

@spalladino spalladino added this to the 0.21.0 milestone Feb 16, 2017
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

Successfully merging this pull request may close these issues.

None yet

5 participants