Comments (11)
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
from httplog.
Found it. The Google API gem uses HTTPClient with the option transparent_gzip_decompression = true
. Working on a fix, stay tuned.
from httplog.
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)
from httplog.
Well, it kind of is in httplog. Lesson learned (again). 😁
Released v1.0.3. Cheers
from httplog.
Thanks for the detailed report, I'll take a look now.
from httplog.
@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 Zlib::DataError
before httplog ever gets a chance to try its own unzip. Could you provide a test that fails with your particular error, or a code snippet using the Drive API that I can use as a basis to write a failing spec?
from httplog.
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.
I was hoping it's the rspec, but those guys said it cannot be.
It's happening in my Rails project so it can be anything in the middle, right?
For now, I just edited the http_log.rb
file locally to catch that exception, and it works fine now.
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...
from httplog.
Whew, got to reproduce that!
Here is the git repo with clean Rails project and just added the Google Cloud API and httplog, and the Rspec test that reproduces that error.
https://github.com/marisveide/reproduce-gzip-error-in-httplog
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
from httplog.
Got it. I'd suggest to delete that repo immediately unless the private key in there is for a dedicated test account...
from httplog.
That's ok, I have created the special test key for just this case.
I will delete the key on the Google Cloud side when you will confirm that the root cause is found and fixed.
from httplog.
Yey, thanks!
It works, perfect!
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). :)
from httplog.
Related Issues (20)
- Is it possible to check programmatically if any external HTTP requests were made after a run? HOT 1
- Exception `Errno::ESPIPE` with chunked transfer encoding and pipe-io as body HOT 1
- Need to require Json even if config.json_log = false
- Crash on frozen string during force_encoding HOT 2
- How to stop logging a PNG binary
- Dependency Dashboard
- Binary body logged HOT 1
- Is adding require 'httplog' necessary? HOT 1
- NoMethodError (undefined method `log' for nil:NilClass)
- No logs and `undefined method [] for nil:NilClass`, Rails 7 HOT 7
- Version 1.6 Changelog Documentation HOT 2
- Allow/block the logging on runtime HOT 3
- Allow regexp on params filter HOT 2
- '(not showing binary data)' when the content-type is text/html HOT 1
- are aws-sdk / amazon request logs also visible through httplog HOT 2
- Bug: Ethon adapter fails when response headers are empty HOT 2
- question: is blacklisting supposed to prevent the request from being sent? HOT 2
- Support for production? HOT 1
- Action Required: Fix Renovate Configuration
- HTTP gem does not work with this gem HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httplog.