Giter Site home page Giter Site logo

Comments (11)

marisveide avatar marisveide commented on August 19, 2024 1

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.

trusche avatar trusche commented on August 19, 2024 1

Found it. The Google API gem uses HTTPClient with the option transparent_gzip_decompression = true. Working on a fix, stay tuned.

from httplog.

trusche avatar trusche commented on August 19, 2024 1

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.

trusche avatar trusche commented on August 19, 2024 1

Well, it kind of is in httplog. Lesson learned (again). 😁

Released v1.0.3. Cheers

from httplog.

trusche avatar trusche commented on August 19, 2024

Thanks for the detailed report, I'll take a look now.

from httplog.

trusche avatar trusche commented on August 19, 2024

@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.

marisveide avatar marisveide commented on August 19, 2024

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.

marisveide avatar marisveide commented on August 19, 2024

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.

trusche avatar trusche commented on August 19, 2024

Got it. I'd suggest to delete that repo immediately unless the private key in there is for a dedicated test account...

from httplog.

marisveide avatar marisveide commented on August 19, 2024

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.

marisveide avatar marisveide commented on August 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.