-
Notifications
You must be signed in to change notification settings - Fork 437
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
Header Response not case insensitive #227
Comments
Hi @dallasrpi, |
Ok, net/http downcases it: https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L17. |
+1 for downcasing the response headers. On Wed, Oct 31, 2012 at 3:34 PM, Hans Hasselberg
|
Convinced. |
Fixed in 256c954. |
Awesome thanks for your contributions! |
This seems like a pretty big backwards-incompatible change. Code that worked fine with 0.5.0 (using something like According to the principles of Semantic Versioning, you should only make backwards-incompatible changes in major releases, so if you care to follow those principles, you should release another 0.5.x release with a fix back to the old behavior and then you can release this in 1.0. If you want to provide case-insensitive access to get headers (which is a useful feature), there are ways to get it without breaking backwards-incompatibility; for example, you could change |
…case header keys. See typhoeus/typhoeus#227 for more info. This is a hack that hopefully we won't have to do in the future, but it'll work for now.
I came up with a fix to get VCR green again, but it's a hack more than anything else. There are a couple of issues at play here:
In the future, please consider running the VCR and WebMock test suites before cutting typhoeus releases; they serve as nice regression suites to make sure you haven't unintentionally broken backwards compatibility and would have surfaced these issues so we could work out the details before this API became public. |
BTW, here's one way to make a hash that keeps the original casing (and thus, remains backwards-compatible) while allowing case-insensitive access: def case_insensitive_hash(hash)
normalized_hash = hash.each_with_object({}) do |(k, v), h|
h[k.downcase] = v
end
case_insensitive = hash.dup
case_insensitive.default_proc = Proc.new do |h, k|
normalized_hash[k.downcase]
end
case_insensitive
end Essentially, it sets the hash's |
@myronmarston thanks for looking into it. I fixed this bug in ced7fc7. I try to stick to semantic versioning and didn't intend to introduce a backwards incompatibility. But I did follow it:
I totally agree with your first comment nevertheless!
Regarding your third comment: Thanks, I'll check it out! |
Will do that from now on! |
So, not sure if this is related, but upgrading from response = Typhoeus::Request.new("www.example.com").run
content_type = response.headers_hash[:content_type]
location = response.headers_hash[:location] Previously, these would return individual header values as expected. Now, both statements above return the same thing (a hash): {"Location"=>"http://www.iana.org/domains/example/", "Server"=>"BigIP", "Connection"=>"Keep-Alive", "Content-Length"=>"0"} Any help? |
@findchris |
Right, but previously that code worked correctly, and I was able to retrieve the desired values from the hash using those symbolized, lowercase keys. -Chris On Jan 7, 2013, at 12:44 AM, Hans Hasselberg notifications@github.com wrote:
|
Further illustration: 1.9.2p320 :013 > response.headers_hash
=> {"Location"=>"http://www.iana.org/domains/example/", "Server"=>"BigIP", "Connection"=>"Keep-Alive", "Content-Length"=>"0"}
1.9.2p320 :014 > response.headers_hash[:location]
=> {"Location"=>"http://www.iana.org/domains/example/", "Server"=>"BigIP", "Connection"=>"Keep-Alive", "Content-Length"=>"0"}
1.9.2p320 :015 > response.headers_hash["location"]
=> "http://www.iana.org/domains/example/" So: Getting a value by symbol returns the full |
@i0rek I can definitely switch from symbols to string keys, but it is just surprising that symbols once worked and now they don't. |
Actually, simply using string keys doesn't behave as expected either: 1.9.2p320 :020 > response.headers['content-type']
=> {"Location"=>"http://www.iana.org/domains/example/", "Server"=>"BigIP", "Connection"=>"Keep-Alive", "Content-Length"=>"0"} It seems that when a header key is not recognized, it simply returns the entire |
@findchris this is not far away from expected behavior! |
@i0rek What am I missing here? If the hash does not contain the specified key, it returns itself (a hash). That is not surprising? Following Ruby hash semantics, a My point is that this behavior has changed drastically between |
@findchris so sorry - this was a typo! you are right!! it is very surprising! |
@i0rek Anything I can do to help? Are symbolized keys not acceptable any more? |
@i0rek Good news: progress! I was viewing the source for header.rb in master (https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/response/header.rb). I noticed the 1.9.2p320 :008 > response.headers['does_not_exist']
=> nil So, this issue is fixed in master. Can you release The only remaining issue is that symbols no longer work as Cheers. |
@findchris oh this is awesome! I would love to release 0.5.4 but it fails on ruby 1.8.7. The problem is that there is no |
@i0rek -- here's one way I've dealt with the lack of You might be able to use the same technique. |
Thanks - thats great!! |
@i0rek Are you working on this or do you want me to? |
@findchris Would be great if you could do that! |
@i0rek Pull request is here: #259 Thanks |
#259 has been merged. Thanks @i0rek. Can you release |
@findchris here comes access via symbols: 0f9887d |
@i0rek Excellent. Now the |
Thanks. I'll try it out. |
This still happens with |
Its pretty common to have headers use "Content-Length" or "Content-length" or "Etag" vs "ETag" . This presents a problem when you don't know which version is coming down the pike. An obvious work around is to iterate the headers object and lowercase the keys but just noting it makes this feature a little less usable.
The text was updated successfully, but these errors were encountered: