diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/webrick/httpproxy.rb | 14 | ||||
-rw-r--r-- | lib/webrick/httputils.rb | 10 | ||||
-rw-r--r-- | lib/webrick/server.rb | 6 |
3 files changed, 22 insertions, 8 deletions
diff --git a/lib/webrick/httpproxy.rb b/lib/webrick/httpproxy.rb index c5ed44f1da..14e3499775 100644 --- a/lib/webrick/httpproxy.rb +++ b/lib/webrick/httpproxy.rb @@ -15,6 +15,14 @@ require "net/http" Net::HTTP::version_1_2 if RUBY_VERSION < "1.7" module WEBrick + NullReader = Object.new + class << NullReader + def read(*args) + nil + end + alias gets read + end + class HTTPProxyServer < HTTPServer def initialize(config) super @@ -111,6 +119,7 @@ module WEBrick proxy_port = proxy.port if proxy.userinfo credentials = "Basic " + [proxy.userinfo].pack("m*") + credentials.chomp! header['proxy-authorization'] = credentials end end @@ -171,6 +180,7 @@ module WEBrick proxy_request_line = "CONNECT #{host}:#{port} HTTP/1.0" if proxy.userinfo credentials = "Basic " + [proxy.userinfo].pack("m*") + credentials.chomp! end host, port = proxy.host, proxy.port end @@ -211,6 +221,10 @@ module WEBrick end res.send_response(ua) access_log(@config, req, res) + + # Should clear request-line not to send the sesponse twice. + # see: HTTPServer#run + req.parse(NullReader) rescue nil end begin diff --git a/lib/webrick/httputils.rb b/lib/webrick/httputils.rb index 18e3e25887..e45d8e0499 100644 --- a/lib/webrick/httputils.rb +++ b/lib/webrick/httputils.rb @@ -179,14 +179,14 @@ module WEBrick if value parts = value.split(/,\s*/) parts.each {|part| - if m = %r{^([^\s,]+?)(?:;\s*q=([\d]+(?:\.[\d]+)))?$}.match(part) - lang = m[1] + if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) + val = m[1] q = (m[2] or 1).to_f - tmp.push([lang, q]) + tmp.push([val, q]) end } - tmp = tmp.sort_by{|lang, q| -q} - tmp.collect!{|lang, q| lang} + tmp = tmp.sort_by{|val, q| -q} + tmp.collect!{|val, q| val} end return tmp end diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb index 48d9fcd4ec..47ba4c700f 100644 --- a/lib/webrick/server.rb +++ b/lib/webrick/server.rb @@ -31,9 +31,9 @@ module WEBrick exit!(0) if fork Dir::chdir("/") File::umask(0) - [ STDIN, STDOUT, STDERR ].each{|io| - io.reopen("/dev/null", "r+") - } + STDIN.reopen("/dev/null") + STDOUT.reopen("/dev/null", "w") + STDERR.reopen("/dev/null", "w") yield if block_given? end end |