Skip to content
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::BufError #125

Closed
jvenezia opened this issue Mar 11, 2015 · 6 comments
Closed

Zlib::BufError #125

jvenezia opened this issue Mar 11, 2015 · 6 comments

Comments

@jvenezia
Copy link

This code raises an Zlib::BufError, for this specific url.

url = 'https://www.mediquality.net/fr/web/MediQuality/-/en-suede-la-cigarette-electronique-est-un-medicament-selon-la-justice'
title = MetaInspector.new(url, retries: 0, download_images: false).title

Is it possible to find a workaround? Or is the response is just not acceptable to be able to extract something?

Thanks

@jaimeiniesta
Copy link
Owner

Thanks for the report. I confirm I get this on Ruby 2.1, this is the related exception:

http://ruby-doc.org/stdlib-2.2.0/libdoc/zlib/rdoc/Zlib/BufError.html

On Ruby 2.2, I get this instead:

TypeError: exception object expected
from /Users/jaime/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/net/http/response.rb:266:in `raise'

What's your Ruby version?

@jaimeiniesta
Copy link
Owner

There seems to be a bug on Ruby's Net::HTTP. We need to understand this in order to find the cure, as Net:HTTP is the adapter we're using:

https://github.com/jaimeiniesta/metainspector/blob/master/lib/meta_inspector/request.rb#L56

I've tried using Excon as the adapter, and in that case the exception raised is FaradayMiddleware::RedirectLimitReached. But we cannot just simply replace Net::HTTP by Excon, this would require changing most of the specs that mock net requests (will do if needed).

@jaimeiniesta
Copy link
Owner

Found it! It seems to be related with servers returning malformed compressed responses and Net::HTTP trying to decompress them. A better explanation can be found here:

lostisland/faraday#337

A workaround is using these headers:

MetaInspector.new(url, headers: {'Accept-Encoding' => 'identity'})

@jaimeiniesta
Copy link
Owner

I think this is a good default header, so I've released 4.4.0 that includes this.

@jvenezia
Copy link
Author

@jaimeiniesta Awesome :) Thanks a lot for your reactivity and this awesome gem !

@jaimeiniesta
Copy link
Owner

You're welcome! Thanks for catching this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants