Actions
Feature #14896
openExpose Net::HTTPResponse socket for integration with libraries expecting an IO
Status:
Open
Assignee:
-
Target version:
-
Description
As several stdlib libraries support reading from IO-compatible objects (e.g. Zlib::GzipReader, Gem::Package::TarReader), would you be open to making the socket of a Net::HTTPResponse public?
This would enable such use cases as streaming a .tar.gz file with the following code:
uri = URI('http://www.example.com/huge.tar.gz')
Net::HTTP.start(uri.host, uri.port) do |http|
http.request_get(uri) do |response|
Zlib::GzipReader.wrap(response.socket) do |gz|
Gem::Package::TarReader.new(gz) do |tar|
tar.each do |entry|
yield entry.read
end
end
end
end
end
We could document this with the same caveat as when passing a block for streaming bodies: noting that the response will not contain a "(meaningful) body" if the user does anything with the underlying socket.
Files
Actions
Like0
Like0