BUG: small glitch in Net:HTTP when adding custom headers

M

Michal

Hi,

today I was toying a bit with Net:HTTP and found small glitch
in HTTPGenericRequest#initialize ... line 1106 reads:

@header[key] = v.strip

which fails on NoMethodError when value of added header is not
String (it was triggered by Fixnum in my case).

In my opinion it should be:

@header[key] = v.to_s.strip

Am I right?

Regards,
W.

PS:

wejn@ns ~ $ ruby --version
ruby 1.8.2 (2004-11-06) [i686-linux]

wejn@ns ~ $ fgrep '$Id' /usr/lib/ruby/1.8/net/http.rb
# $Id: http.rb,v 1.100.2.6 2004/04/18 23:20:32 nobu Exp $
 
M

Minero Aoki

Hi,

In mail "BUG: small glitch in Net:HTTP when adding custom headers"
Michal said:
today I was toying a bit with Net:HTTP and found small glitch
in HTTPGenericRequest#initialize ... line 1106 reads:

@header[key] = v.strip

which fails on NoMethodError when value of added header is not
String (it was triggered by Fixnum in my case).

I think this is the right behavior.
An header field is a String, you should provide a String.
Instant #to_s call will hide some kind of bugs (e.g. nil).

Regards,
Minero Aoki
 
S

Sam Roberts

Quoteing (e-mail address removed), on Sat, Nov 27, 2004 at 03:28:50PM +0900:
Hi,

In mail "BUG: small glitch in Net:HTTP when adding custom headers"
Michal said:
today I was toying a bit with Net:HTTP and found small glitch
in HTTPGenericRequest#initialize ... line 1106 reads:

@header[key] = v.strip

which fails on NoMethodError when value of added header is not
String (it was triggered by Fixnum in my case).

I think this is the right behavior.
An header field is a String, you should provide a String.
Instant #to_s call will hide some kind of bugs (e.g. nil).

Yes, but #to_str would not hide a nil bug:

irb(main):002:0> nil.to_str
NoMethodError: undefined method `to_str' for nil:NilClass
from (irb):2

Also, when you get a NoMethodError saying there is no #to_str you will
think "oops, i should have passed a String", but when you get a
NoMethodError of #strip you might instead have to search the Net::HTTP
code trying to find out what was expected.

These are my thoughts... I always call #to_XXX on my args, because I am
tired of searching through library code trying to find what went wrong
(wrong in my code, of course, but it can show up much later if the
library just stores the object and doesn't use it right away).

Cheers,
Sam
 

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top