-
Notifications
You must be signed in to change notification settings - Fork 74
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
"Zlib::GzipFile::Error: not in gzip format", when using with Google Drive API #58
Comments
I found that it might be unzipped by rspec, so the httplog gets an exception when trying to unzip the content again. Suggesting the following fix in the http_log.rb file "log_body" method - basically to rescue from the exception of unzipping not zipped body: if encoding =~ /gzip/ && body && !body.empty?
begin
sio = StringIO.new(body.to_s)
gz = Zlib::GzipReader.new(sio)
body = gz.read
rescue Zlib::GzipFile::Error => e
log("Error decompressing body: #{e.message}")
end
end |
Thanks for the detailed report, I'll take a look now. |
@marisveide I'm having a hard time reproducing this in test code - if I simply send a text file with a gzip encoding, ruby's net/http raises a |
Thank you @trusche for looking into this... I really appreciate that. Yeah, I tried to make the simple Ruby file that would reproduce that issue, but I also didn't succeed - works like a charm. It looks like there is some gem in the middle that catches it. Strange is that this error happens only when I run the test code from rspec. When I just run the code even in rails console, it also works fine. It's happening in my Rails project so it can be anything in the middle, right? But I will try to create a sample that reproduces that issue. I realize how wrong it is to fix an issue that's not reproducible in the first place... |
Whew, got to reproduce that! This is that test to run, to get that error: https://github.com/marisveide/reproduce-gzip-error-in-httplog/blob/master/spec/lib/google_drive_spec.rb Related issue in google-api-ruby-client repo: googleapis/google-api-ruby-client#661 |
Got it. I'd suggest to delete that repo immediately unless the private key in there is for a dedicated test account... |
That's ok, I have created the special test key for just this case. |
Found it. The Google API gem uses HTTPClient with the option |
Could you please try master, this should no longer throw an error but add a line to the log file stating that gzip decompression failed (same as your solution, really) |
Yey, thanks! Thank you so much for fixing this. Although the root cause is not in httplog - proves the value of "defensive programming" (never trust the input). :) |
Well, it kind of is in httplog. Lesson learned (again). 😁 Released v1.0.3. Cheers |
When using Google Drive API gem, for some reason the encoding is set to gzip, but the body is actually text/json.
So the httplog crashes on that:
I know it may be better to wait for Google to fix the place where it decodes the body earlier, to reset the encoding or something, but it might never happen.
So I suggest to fix this place in code to handle the cases when the encoding is set to "gzip", but body is actually not gzipped anymore.
The text was updated successfully, but these errors were encountered: