Expose Net::HTTPResponse socket for integration with libraries expecting an IO
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.
Updated by shevegen (Robert A. Heiler) over 5 years ago
I have nothing useful to add to the issue at hand as I only very
rarely use Net:: directly (my use cases usually start and end with
open-uri which I think is great) - the reason I comment here is to
suggest to you to add your feature request to the next developer
meeting that is bound to happen in two weeks:
The discussions there often help get things moving, either because
of direct approval by matz, or by requestung some feedback or
making modifications/suggestions to the issue at hand.
The use case was mentioned as well ("streaming a .tar.gz file"; I guess
it applies to all compressed files like .zip or .tar.xz and so forth).
If I may suggest, the documentation could mention the use case and/or
provide examples to it and clarifications. For example, reading "meaningful
body" leads me to wonder in what context the body is meant here (I
assume to the method itself) and what is meaningful and what is not
or what is meant with it.