------ 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;"> class HTTP</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> def HTTP.querystring(params, sep #39;&')</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;"> if params.keys.length
> 0</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;"> p arams.keys.sort.collect do |k|</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">
q arams[k].collect { |v| CGI.escape(k) + ' 39; + CGI.escape(v) }</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;"> q CGI.escape(k) + ' 39; ] if params[k] ""
</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;"> q.join(sep)</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">
end</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;"> p.join(sep)</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">
else</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;"> nil</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">
end</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;"> end</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">
end</span><br styleont-family: courier new,monospace;"><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;"> module HTTPHeader</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> def set_form_data(params, sep #39;&')</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;"> self.body
et::HTTP.querystring(params, sep)</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;"> self.content_type #39;application/x-www-form-urlencoded'</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> end</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;"> alias form_data et_form_data</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> end</span><br styleont-family: courier new,monospace;"><span styleont-family: courier new,monospace;">end<br><br> # Client code.<br> uri RI.parse(server) + path
<br> http et::HTTP.new(uri.host, uri.port)<br> uri ri.to_s<br> http.start do |http|<br> http.read_timeout read_timeout<br> if method 'GET'<br> if params.length > 0<br> params et::
HTTP.querystring(params)<br> uri quot;#{uri}?#{params}"<br> end<br> q et::HTTP::Get.new(uri)<br> else<br> q et::HTTP::Post.new(uri)<br> q.form_data arams<br> 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'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;"> class HTTP</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> def HTTP.post_form_with_timeout(url, params, read_timeout)</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> req ost.new(url.path)</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> req.form_data arams</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> req.basic_auth url.user, url.password if url.user</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> new(url.host, url.port).start {|http|</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> http.read_timeout ead_timeout</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> http.request(req)</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> }</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> end</span><br styleont-family: courier new,monospace;">
<span styleont-family: courier new,monospace;"> 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 class g">
<span styleont-family: courier new,monospace;"></span><br><br>Mihai<br><br></span>
------ art_17300_1066367.1175629179532--