From 635d13a8b7eb17f65462ea44c9911755a45ab8c7 Mon Sep 17 00:00:00 2001 From: nahi Date: Fri, 24 Jun 2011 11:05:59 +0000 Subject: * lib/webrick/httprequest.rb (setup_forwarded_info): Parsing request header failed when the request is from 2 or more Apache reverse proxies. It's said that all X-Forwarded-* headers will contain more than one (comma-separated) value if the original request already contained one of these headers. Since we could use these values as Host header, we choose the initial(first) value. See #4922. * test/webrick/test_httprequest.rb (test_forwarded): Test it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/webrick/test_httprequest.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/webrick') diff --git a/test/webrick/test_httprequest.rb b/test/webrick/test_httprequest.rb index 2d96c2fcb0..d8467d4b4e 100644 --- a/test/webrick/test_httprequest.rb +++ b/test/webrick/test_httprequest.rb @@ -303,6 +303,28 @@ class TestWEBrickHTTPRequest < Test::Unit::TestCase assert_equal(443, req.port) assert_equal("234.234.234.234", req.remote_ip) assert(req.ssl?) + + msg = <<-_end_of_message_ + GET /foo HTTP/1.1 + Host: localhost:10080 + Client-IP: 234.234.234.234 + X-Forwarded-Proto: https + X-Forwarded-For: 192.168.1.10 + X-Forwarded-Host: forward1.example.com:1234, forward2.example.com:5678 + X-Forwarded-Server: server1.example.com, server2.example.com + X-Requested-With: XMLHttpRequest + Connection: Keep-Alive + + _end_of_message_ + msg.gsub!(/^ {6}/, "") + req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req.parse(StringIO.new(msg)) + assert_equal("server1.example.com", req.server_name) + assert_equal("https://forward1.example.com:1234/foo", req.request_uri.to_s) + assert_equal("forward1.example.com", req.host) + assert_equal(1234, req.port) + assert_equal("234.234.234.234", req.remote_ip) + assert(req.ssl?) end def test_continue_sent -- cgit v1.2.3