# \[bug\] nice exception in Net::HTTP::HTTPHeader

**URL:** <https://www.ruby-forum.com/t/bug-nice-exception-in-net-httpheader/129931>\
**Category:** Ruby\
**Created:** [February 22, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/bug-nice-exception-in-net-httpheader/129931 "2008-02-22T20:25:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ustalov\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/df705f/32.png) [@Ustalov\_D](https://www.ruby-forum.com/u/Ustalov_D)\
**Post date:** [February 22, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/bug-nice-exception-in-net-httpheader/129931/1 "2008-02-22T20:25:44Z")

</div>

hello.

method initialize\_http\_header() of the Net::HTTP::HTTPHeader doesn’t  
check the type of the ‘value’, and crashes with exception:  
—8\<—  
/usr/lib/ruby/1.8/net/http.rb:1142:in `initialize_http_header': undefined method `strip’ for 1.43:Float (NoMethodError)  
from /usr/lib/ruby/1.8/net/http.rb:1140:in `each' from /usr/lib/ruby/1.8/net/http.rb:1140:in `initialize\_http\_header’  
from /usr/lib/ruby/1.8/net/http.rb:1472:in `initialize' from /usr/lib/ruby/1.8/net/http.rb:1588:in `initialize’  
from /usr/lib/ruby/1.8/net/http.rb:845:in `new' from /usr/lib/ruby/1.8/net/http.rb:845:in `post’  
—\>8—

I think, we need to cast any ‘value’ to String in the  
initialize\_http\_header()  
—8\<—  
def initialize\_http\_header(initheader)  
@header = {}  
return unless initheader  
initheader.each do |key, value|  
warn “net/http: warning: duplicated HTTP header: #{key}” if  
key?(key) and $VERBOSE  
@header[key.downcase] = [value.strip]  
end  
end  
—\>8—  
Maybe, we should use ‘value.to\_s.strip’ instead of ‘value.strip’?

How to reproduce this bug:  
—8\<—  
#!/usr/bin/env ruby

# resolve any URI

require ‘uri’  
url = URI.parse(“[http://paste.org.ru/](http://paste.org.ru/)”) # put your favourite site  
here!

# define the data

data = ‘data=oops’

# prepare the request

require ‘net/http’  
http = Net::HTTP.new(url.host, url.port)

headers = {  
‘Content-Length’ =\> data.size  
}

resp = http.post(url.path, data, headers)  
—\>8—

My system is:  
Fedora 8 (Werewolf) i386, ruby 1.8.6

---

<div class="post-metadata">

**Author:** ![Ustalov\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/df705f/32.png) [@Ustalov\_D](https://www.ruby-forum.com/u/Ustalov_D)\
**Post date:** [February 22, 2008, 8:48pm UTC](https://www.ruby-forum.com/t/bug-nice-exception-in-net-httpheader/129931/2 "2008-02-22T20:48:12Z")

</div>

On Fri, Feb 22, 2008 at 8:24 PM, Ustalov D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> hello.
> 
> method initialize\_http\_header() of the Net::HTTP::HTTPHeader doesn’t  
> check the type of the ‘value’, and crashes with exception:

please, file a bug in ruby’s tracker:

[http://rubyforge.org/tracker/index.php?group\_id=426&atid=1698](http://rubyforge.org/tracker/index.php?group_id=426&atid=1698)

---

<div class="post-metadata">

**Author:** ![Ustalov\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/df705f/32.png) [@Ustalov\_D](https://www.ruby-forum.com/u/Ustalov_D)\
**Post date:** [February 22, 2008, 9:01pm UTC](https://www.ruby-forum.com/t/bug-nice-exception-in-net-httpheader/129931/3 "2008-02-22T21:01:13Z")

</div>

On 23 ÆÅ×, 00:47, Jano S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> please, file a bug in ruby’s tracker:
> 
> [http://rubyforge.org/tracker/index.php?group\_id=426&atid=1698](http://rubyforge.org/tracker/index.php?group_id=426&atid=1698)

done:  
[http://rubyforge.org/tracker/index.php?func=detail&aid=18302&group\_id=426&atid=1698](http://rubyforge.org/tracker/index.php?func=detail&aid=18302&group_id=426&atid=1698)

thanks.
