[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Potential bug in Net::HTTP, and tentative patch

Nobuyoshi Nakada

4/13/2009 11:20:00 AM

Hi,

At Mon, 13 Apr 2009 12:40:32 +0900,
Yves-Eric Martin wrote in [ruby-talk:333704]:
> In http.rb, line 2236 the "read_chunked" function calls
> @socket.readline. This "readline" function, in protocol.rb line 126,
> calls readuntil("\n"). This works fine if the data chunk is
> "\n-terminated", but throws an EOFError if it is not.

Not "\n-terminated".

According to RFC2616 and RFC2068, chunks consist from
chunk-size and chunk-body, and the chunked-body is terminated
by "0" size chunk.

That is, the response doesn't seem to follow the RFCs.

--
Nobu Nakada

3 Answers

Yves-Eric Martin

4/14/2009 3:33:00 AM

0

Thank you for pointing me to the RFC. Indeed, the response does not
seem RFC-compliant...

Other than my quick and dirty patch, is there a way to tell Net::HTTP
to ignore the EOFError and accept non-compliant input? Again, the point
is that an image, which displays fine in Internet Explorer, Firefox and
Safari, cannot be downloaded with Net::HTTP. While I understand the
"not RFC-compliant" argument, for practical reasons, it does seem a bit
limiting...

Thank you,


PS: I will also contact the administrator of the problem site regarding this
RFC compliance issue.

--
Yves-Eric


Nobuyoshi Nakada wrote:
> Hi,
>
> At Mon, 13 Apr 2009 12:40:32 +0900,
> Yves-Eric Martin wrote in [ruby-talk:333704]:
>
>> In http.rb, line 2236 the "read_chunked" function calls
>> @socket.readline. This "readline" function, in protocol.rb line 126,
>> calls readuntil("\n"). This works fine if the data chunk is
>> "\n-terminated", but throws an EOFError if it is not.
>>
>
> Not "\n-terminated".
>
> According to RFC2616 and RFC2068, chunks consist from
> chunk-size and chunk-body, and the chunked-body is terminated
> by "0" size chunk.
>
> That is, the response doesn't seem to follow the RFCs.
>
>


Nobuyoshi Nakada

4/14/2009 4:26:00 AM

0

Hi,

At Tue, 14 Apr 2009 12:33:01 +0900,
Yves-Eric Martin wrote in [ruby-talk:333820]:
> Other than my quick and dirty patch, is there a way to tell Net::HTTP
> to ignore the EOFError and accept non-compliant input? Again, the point
> is that an image, which displays fine in Internet Explorer, Firefox and
> Safari, cannot be downloaded with Net::HTTP. While I understand the
> "not RFC-compliant" argument, for practical reasons, it does seem a bit
> limiting...

See rdoc of Net::HTTPResponse#read_body and
Net::HTTP#request_get.

out = "" # or open(destfile, "wb")
begin
Net::HTTP.get_response(uri) do |res|
res.read_body {|s| out << s}
end
rescue EOFError
end

--
Nobu Nakada

Yves-Eric Martin

4/14/2009 8:33:00 AM

0

Works like a charm!

Thank you Nobu for your great help. I owe you a beer.


--
Yves-Eric


Nobuyoshi Nakada wrote:
> See rdoc of Net::HTTPResponse#read_body and
> Net::HTTP#request_get.
>
> out = "" # or open(destfile, "wb")
> begin
> Net::HTTP.get_response(uri) do |res|
> res.read_body {|s| out << s}
> end
> rescue EOFError
> end
>
>