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: buffer error #991

Open
mattandayo opened this issue Jun 11, 2019 · 3 comments
Open

Zlib::BufError: buffer error #991

mattandayo opened this issue Jun 11, 2019 · 3 comments

Comments

@mattandayo
Copy link

mattandayo commented Jun 11, 2019

Basic Info

  • Faraday Version: 0.12.2
  • Ruby Version: 2.5.3

Issue description

I have a rails app with requesting a api by http.
See example below:

conn = Faraday::Connection.new(
           url: 'API base url',
           headers: {
             'apikey': 'API Key',
             'content-type': 'application/json'
           }
         )

res = conn.post do |req|
  req.url '/end_point'
  req.body = 'json'
end

I succeeded the way that is requesting with the same content by curl, but I didn't succeeded the way with using faraday.
client.post raised Zlib::BufError .
See example below:

res = conn.post do |req|
  req.url 'end_point'
  req.body = 'json'
end

=>
Zlib::BufError: buffer error
from /usr/local/lib/ruby/2.5.3/net/http/response.rb:366:in `finish'

Is there any settings in Faraday that I'm missing ?
Any help would be greatly appreciated. Thanks

@iMacTia
Copy link
Member

iMacTia commented Jun 12, 2019

@mattandayo since the last stack trace call is on Net::HTTP, I'd first like to confirm this is a Faraday issue. Have you tried performing the same request using pure Net::HTTP Ruby client?

@technoweenie
Copy link
Member

A Zlib error implies issues regarding gzip encoding. Net::HTTP sends an Accept-Encoding header to enable compression automatically.

Some questions:

  1. What HTTP headers from the request is the Rails app seeing? It should require an Accept-Encoding header specifying gzip or deflate before it compresses the response body.
  2. What HTTP headers is the Rails app sending? If it's gzipping the response, there should be a Content-Encoding header saying that.

Since Faraday is raising an exception, it may not be that useful in debugging this. A full curl -v ... command for the exact same request could help.

There's the possibility that the Zlib error is raised because irb is calling Faraday::Response#inspect. You can get around that like this:

require 'pp'
res = conn.post do |req|
  req.url 'end_point'
  req.body = 'json'
end ; nil # this prevents irb from calling res.inspect
pp res.headers

@grosser
Copy link
Contributor

grosser commented Jul 2, 2019

at least faraday should catch this error and re-raise as Faradayish error ?

just saw the same while doing a http get:

Zlib::BufError: buffer error
  File "/usr/local/lib/ruby/2.6.0/net/http/response.rb", line 366, in finish
  File "/usr/local/lib/ruby/2.6.0/net/http/response.rb", line 366, in finish
  File "/usr/local/lib/ruby/2.6.0/net/http/response.rb", line 268, in ensure in inflater
  File "/usr/local/lib/ruby/2.6.0/net/http/response.rb", line 267, in inflater
  File "/usr/local/lib/ruby/2.6.0/net/http/response.rb", line 283, in read_body_0
  File "/usr/local/lib/ruby/2.6.0/net/http/response.rb", line 204, in read_body
  File "/usr/local/lib/ruby/2.6.0/net/http.rb", line 1229, in block in get
  File "/usr/local/lib/ruby/2.6.0/net/http.rb", line 1518, in block in transport_request
  File "/usr/local/lib/ruby/2.6.0/net/http/response.rb", line 165, in reading_body
  File "/usr/local/lib/ruby/2.6.0/net/http.rb", line 1517, in transport_request
  File "/usr/local/lib/ruby/2.6.0/net/http.rb", line 1479, in request
  File "/usr/local/lib/ruby/2.6.0/net/http.rb", line 1472, in block in request
  File "/usr/local/lib/ruby/2.6.0/net/http.rb", line 920, in start
  File "/usr/local/lib/ruby/2.6.0/net/http.rb", line 1470, in request
  File "/usr/local/lib/ruby/2.6.0/net/http.rb", line 1228, in get
  File "/app/vendor/bundle/ruby/2.6.0/gems/faraday-0.15.0/lib/faraday/adapter/net_http.rb", line 80, in perform_request

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

No branches or pull requests

4 participants