# 'net/http' issues

**URL:** <https://www.ruby-forum.com/t/net-http-issues/91013>\
**Category:** Ruby\
**Created:** [April 3, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/net-http-issues/91013 "2007-04-03T20:51:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mihai\_Danila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@Mihai\_Danila](https://www.ruby-forum.com/u/Mihai_Danila)\
**Post date:** [April 3, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/net-http-issues/91013/1 "2007-04-03T20:51:56Z")

</div>

I noticed a while back a few limitations in the Ruby net/http library.

First, the implementation bluntly ignores a crucial part of the HTTP  
protocol, that is, the fact that a parameter may appear multiple times  
in a  
request string. Using a hash behind the scenes, keyed by parameter name,  
Ruby in effect forces a single occurrence of any individual parameter.  
To  
bypass, I had to do:

module Net  
class HTTP  
def HTTP.querystring(params, sep = ‘&’)  
if params.keys.length \> 0  
p = params.keys.sort.collect do |k|  
q = params[k].collect { |v| CGI.escape(k) + ‘=’ +  
CGI.escape(v) }  
q = [CGI.escape(k) + ‘=’] if params[k] == “”  
q.join(sep)  
end  
p.join(sep)  
else  
nil  
end  
end  
end

module HTTPHeader  
def set\_form\_data(params, sep = ‘&’)  
self.body = Net::HTTP.querystring(params, sep)  
self.content\_type = ‘application/x-www-form-urlencoded’  
end  
alias form\_data= set\_form\_data  
end  
end

```
# Client code.
uri = URI.parse(server) + path
http = Net::HTTP.new(uri.host, uri.port)
uri = uri.to_s
http.start do |http|
  http.read_timeout = @read_timeout
  if method == 'GET'
    if params.length > 0
      params = Net::HTTP.querystring(params)
      uri = "#{uri}?#{params}"
    end
    q = Net::HTTP::Get.new(uri)
  else
    q = Net::HTTP::Post.new(uri)
    q.form_data = params
  end

```

Second, I had to overwrite HTTP.post\_form\_with\_timeout for it to work  
correctly. (I forget what the actual bug was, but while I’m at it)

module Net  
class HTTP  
def HTTP.post\_form\_with\_timeout(url, params, read\_timeout)  
req = Post.new(url.path)  
req.form\_data = params  
req.basic\_auth url.user, url.password if url.user  
new(url.host, url.port).start {|http|  
http.read\_timeout = read\_timeout  
http.request(req)  
}  
end  
end  
end

What is the status of these issues?

I used ruby184-16p3.exe on WinXP.

Mihai
