From: Sam Roberts Date: 2004-11-28T01:28:23+09:00 Subject: Re: BUG: small glitch in Net:HTTP when adding custom headers Quoteing aamine@loveruby.net, on Sat, Nov 27, 2004 at 03:28:50PM +0900: > Hi, > > In mail "BUG: small glitch in Net:HTTP when adding custom headers" > Michal wrote: > > > 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