Open Gargron opened 4 years ago
The error is raised in the Redirector
(lib/http/redirector.rb:59
) when it tries to flush the body of the first response:
res = HTTP.headers('Accept-Encoding' => 'gzip').get(url)
zlib = Zlib::Inflate.new(32 + Zlib::MAX_WBITS)
zlib.inflate(res.to_s)
zlib.finish # => Zlib::BufError: buffer error
res.to_s # => " "
res.headers['Content-Encoding'] # => "gzip"
IMO returned response is faulty. It shouldn't contain Content-Encoding
header if body is not compressed.
On the other hand it should be easy to "fix" it on http-rb side by skipping decompression when body is flushed.
Example request:
immediately raises:
If you fetch the URL without
use(:auto_inflate)
, read the body into a string, then feed it into Zlib in full, then it's correctly decoded without errors:It must be related to how the chunks are read but I don't know enough about Zlib to understand why.