Ruby 2.2.5 + net/http = hideous header
![]() |
Photo from Pexels |
I'm using the gem HTTParty which is mostly a nicer interface to the Net::HTTP libs that come with Ruby. You use these libraries to make HTTP requests and handle web stuff. So I was working on my GnipApi gem to get some things fixed. And then I found out something was wrong.
I use HTTParty to connect to a stream that sends some data. The server compresses the responses in GZip, so you have to specify that you'll accept and decode GZip on the request. So I made something like this:
HTTParty.get some_uri, :headers => {'Accept-Encoding' => 'gzip'}, :basic_auth => some_auth, :stream_body => true do |data| yield(data) endAll looks fine, right? WRONG!! Everything broke down. Upon inspection I was getting binary data direclty, which is a sign GZip is not being decompressed.
After a few hours, I reach a site where they were talking about something broken and GZip not being processed, however it wasn't my problem. In a moment of inpiration I changed the header 'Accept-Encoding' to 'accept-encoding', with no luck, and then to 'accept-Encoding', and guess what? It got fixed.
Why this happened? No idea, but I suspect something is horribly hardcoded down on Net::HTTP. I'll update this if I find more info.
If you have problems with Net::HTTP and GZip data, check your header names. It's case sensitive apparently. Not sure what to blame at the moment.