Skip to content
This repository

README request["SOME_HEADER"] documentation incorrect. #542

Closed
CraigStuntz opened this Issue June 29, 2012 · 8 comments

3 participants

Craig Stuntz Konstantin Haase Kashyap
Craig Stuntz

The README says:

request["SOME_HEADER"]      # value of SOME_HEADER header

This is wrong. Rack doesn't put headers in the params hash, just form data and query strings. Sinatra doesn't override this, either.

As far as I can tell, the only way to get request headers is via env.

Kashyap
kgrz commented July 19, 2012

@CraigStuntz Yes. it should be `request.env["SOME_HEADER"]. Mind if I sent a pull request?

Craig Stuntz

@kgrz That's fine, but request["SOME_PARAM"] also has value. It just doesn't include headers. Maybe it should say:

request["SOME_PARAM"]      # value of SOME_PARAM request param

?

Kashyap
kgrz commented July 19, 2012

It returned nil. request cannot be queried that way as far as know. Unlike env which is a hash.

Craig Stuntz

Hmm... The source code and the docs say otherwise. Have you tested?

Kashyap
kgrz commented July 19, 2012

Yes, I've tested it. In the Rack Request docs, it says that [] is a shortcut to 'request.params' hash. This is the GET and POST params hash and not the headers hash. So request["HTTP_REFERER"] returns a nil. However, request[:query] will return "Hello" provided the url is http://localhost/?query=Hello. I've tested the headers part am I'm sure about that. The second part is what I infer from the docs and Rack source.

Sorry about lack of proper formatting. My phone keypad doesn't have a backticks key.

Kashyap
kgrz commented July 19, 2012

Oh. I think you meant the same thing right? :-) Perhaps I got carried away by the capital "SOME_VALUE" there. My mistake.

Konstantin Haase
Owner
rkh commented August 31, 2012

Pull Request for better docs welcome. You'll get karma points.

Kashyap

Modified accordingly: 6ec1aa4

Konstantin Haase rkh referenced this issue from a commit September 04, 2012
Kashyap Issue #542
#542. request["SOME_HEADER"]
is a little confusing since the [] operator on request object is a 
shortcut to the params hash. And thus, request["key"] is same as 
params["key"]. Updated the same thing.
6ec1aa4
Konstantin Haase rkh closed this in ddbba34 September 04, 2012
Konstantin Haase rkh referenced this issue from a commit September 04, 2012
Kashyap Issue #542
#542. request["SOME_HEADER"]
is a little confusing since the [] operator on request object is a 
shortcut to the params hash. And thus, request["key"] is same as 
params["key"]. Updated the same thing.
786fb1c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.