Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
CraigStuntz opened this Issue · 8 comments

3 participants

@CraigStuntz

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.

@kgrz

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

@CraigStuntz

@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

?

@kgrz

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

@CraigStuntz

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

@kgrz

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.

@kgrz

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

@rkh
Owner

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

@kgrz

Modified accordingly: 6ec1aa4

@rkh rkh referenced this issue from a commit
@kgrz kgrz 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
@rkh rkh closed this in ddbba34
@rkh rkh referenced this issue from a commit
@kgrz kgrz 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.