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 hash should downcase keys so canonical header name can be used #38

Closed
cap10morgan opened this issue May 6, 2010 · 4 comments
Closed

Comments

@cap10morgan
Copy link
Contributor

In net-http, when you lookup a header in the headers hash, it overrides the method and downcases the key argument before grabbing the value from the internal data structure. HTTParty should do the same thing.

Right now, for example, doing this: response.headers['Cache-Control'] gives you a nil even though there is a "Cache-Control" header in the HTTP response. response.headers['cache-control'] works, however.

If no one disagrees that this is a bug that needs fixing, I'll take a crack at fixing it in a fork and issue a pull request.

@cap10morgan
Copy link
Contributor Author

@sandro
Copy link
Collaborator

sandro commented May 18, 2010

Thanks for the patch. Generally, I'd love it if HTTParty::Response was more API-compatible with Net::HTTPResponse and this issue is bringing us a little closer to that. While your patch fixes the case-sensitivity issue we'd still be returning a simple hash instead something that acts more like an HTTPResponse object.

In this example, accessing the set-cookie header returns an array when it's accessed through HTTParty while Net::HTTP returns a comma delimited string.

>> r = HTTParty.get('http://github.com'); r.headers['set-cookie']
=> ["csrf_id=5bfd378ae7f1418ef00df0361b2cb5d7; path=/", "_github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly"]
>>
>> r = Net::HTTP.get_response(URI.parse('http://github.com')); r['set-cookie']
=> "csrf_id=bdceb42a51453f0f6f9ee8d2b5acd98a; path=/, _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly"

I'm almost finished , just wanted to give you some context on why I'm moving towards another solution.

@cap10morgan
Copy link
Contributor Author

Sounds good to me. Thanks for the explanation.

@sandro
Copy link
Collaborator

sandro commented May 18, 2010

Response headers accessible with mixed-case keys

HTTParty::Response#response now returns the Net::HTTPResponse object for
the request. Method missing now attempts to call the missing method on the
HTTPResponse object when it doesn't exist on the parsed response
object, i.e.
HTTParty.get('http://example.com').get_fields('content-type')

Closed by 179ef87

ntalbott pushed a commit to ntalbott/httparty that referenced this issue May 4, 2012
HTTParty::Response#response now returns the Net::HTTPResponse object for
the request. Method missing now attempts to call the missing method on the
HTTPResponse object when it doesn't exist on the parsed response
object, i.e.
HTTParty.get('http://example.com').get_fields('content-type')

Closes jnunemakergh-38
This issue was closed.
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

2 participants