Project

General

Profile

Actions

Bug #6957

closed

Net::HTTP#request_get bug

Added by kl (Kalle Lindström) almost 10 years ago. Updated almost 10 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.3p194 (2012-04-20) [i386-mingw32]
Backport:
[ruby-core:47383]

Description

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

Updated by naruse (Yui NARUSE) almost 10 years ago

  • Status changed from Open to Rejected

I understand what you say, but it is because of compatibility.
Please use break as you wrote.

Updated by drbrain (Eric Hodel) almost 10 years ago

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

Actions

Also available in: Atom PDF