Issue #6957 has been updated by drbrain (Eric Hodel).


Also, if you only want content-length, a HEAD request will be sufficient:

  [...]
  http.head uri.request_uri do |req|
    puts req['content-length']
  end
----------------------------------------
Bug #6957: Net::HTTP#request_get bug
https://bugs.ruby-lang.org/issues/6957#change-29161

Author: kl (Kalle Lindström)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 1.9.3p194 (2012-04-20) [i386-mingw32]


Hello,

Looking at the source for Net::HTTP#request_get it says that if you pass in a block it will not read the body unless you call #read_body on the response. But when I pass in a block it seems that it reads the when the block exits, even though I did not call #read_body on the request. Consider this example:

url = "http://download.microsoft.com/download/1/6/5/165b076b-aaa9-443d-84f0-73cf11fdcdf8/WindowsXP-KB835935-SP2-ENU.exe"
uri = URI(url)
http = Net::HTTP.new(uri.hostname, uri.port)

http.request_get(uri.request_uri) do |req|
  puts req["content-length"]
end # Program stops here for a long time - it must be downloading the body of the file?

compared to this:

http.request_get(uri.request_uri) do |req|
  puts req["content-length"]
  break # Now this method works as expected, it exits at this point without any delay
end



-- 
http://bugs.ruby-lang.org/