------art_17300_1066367.1175629179532
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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  arams.keys.sort.collect do |k|
          q  arams[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  et::HTTP.querystring(params, sep)
      self.content_type  application/x-www-form-urlencoded'
    end
    alias form_data et_form_data
  end
end

    # Client code.
    uri  RI.parse(server) + path
    http  et::HTTP.new(uri.host, uri.port)
    uri  ri.to_s
    http.start do |http|
      http.read_timeout  read_timeout
      if method 'GET'
        if params.length > 0
          params  et:: HTTP.querystring(params)
          uri  #{uri}?#{params}"
        end
        q  et::HTTP::Get.new(uri)
      else
        q  et::HTTP::Post.new(uri)
        q.form_data  arams
      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  ost.new(url.path)
      req.form_data  arams
      req.basic_auth url.user, url.password if url.user
      new(url.host, url.port).start {|http|
        http.read_timeout  ead_timeout
        http.request(req)
      }
    end
  end
end

What is the status of these issues?

I used ruby184-16p3.exe on WinXP.


Mihai

------art_17300_1066367.1175629179532
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I noticed a while back a few limitations in the Ruby net/http library.<br><br>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:
<br><br><span styleont-family: courier new,monospace;">module Net</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp; class HTTP</span><br styleont-family: courier new,monospace;">

<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; def HTTP.querystring(params, sep  #39;&amp;&#39;)</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if params.keys.length

 &gt; 0</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p  arams.keys.sort.collect do |k|</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q  arams[k].collect { |v| CGI.escape(k) + &#39;39; + CGI.escape(v) }</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q   CGI.escape(k) + &#39;39; ] if params[k] &quot;&quot;
</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q.join(sep)</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p.join(sep)</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nil</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; end</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">

&nbsp; end</span><br styleont-family: courier new,monospace;"><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp; module HTTPHeader</span><br styleont-family: courier new,monospace;">

<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; def set_form_data(params, sep  #39;&amp;&#39;)</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.body

  et::HTTP.querystring(params, sep)</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.content_type  #39;application/x-www-form-urlencoded&#39;</span><br styleont-family: courier new,monospace;">

<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; end</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; alias form_data et_form_data</span><br styleont-family: courier new,monospace;">

<span styleont-family: courier new,monospace;">&nbsp; end</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">end<br><br>&nbsp;&nbsp;&nbsp; # Client code.<br>&nbsp;&nbsp;&nbsp; uri  RI.parse(server) + path
<br>&nbsp;&nbsp;&nbsp; http  et::HTTP.new(uri.host, uri.port)<br>&nbsp;&nbsp;&nbsp; uri  ri.to_s<br>&nbsp;&nbsp;&nbsp; http.start do |http|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http.read_timeout  read_timeout<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if method &#39;GET&#39;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if params.length &gt; 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; params  et::
HTTP.querystring(params)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uri  quot;#{uri}?#{params}&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q  et::HTTP::Get.new(uri)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q  et::HTTP::Post.new(uri)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q.form_data  arams<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end
<br><br styleont-family: courier new,monospace;"></span><br>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&#39;m at it)<br>
<br><span styleont-family: courier new,monospace;">module Net</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">&nbsp; class HTTP</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; def HTTP.post_form_with_timeout(url, params, read_timeout)</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req  ost.new(url.path)</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.form_data  arams</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.basic_auth url.user, url.password if url.user</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new(url.host, url.port).start {|http|</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http.read_timeout  ead_timeout</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http.request(req)</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; end</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">&nbsp; end</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;">end</span><br styleont-family: courier new,monospace;">
<br>
What is the status of these issues?<br><br>
I used ruby184-16p3.exe on WinXP.<br><span classg">

<span styleont-family: courier new,monospace;"></span><br><br>Mihai<br><br></span>

------art_17300_1066367.1175629179532--