Index: test/webrick/test_httprequest.rb =================================================================== --- test/webrick/test_httprequest.rb (revision 30049) +++ test/webrick/test_httprequest.rb (working copy) @@ -3,17 +3,19 @@ require "test/unit" class TestWEBrickHTTPRequest < Test::Unit::TestCase + HTTP_CONFIG = WEBrick::Config::HTTP.merge(:ServerName => 'localhost') + def test_parse_09 msg = <<-_end_of_message_ GET / foobar # HTTP/0.9 request don't have header nor entity body. _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) assert_equal("GET", req.request_method) assert_equal("/", req.unparsed_uri) assert_equal(WEBrick::HTTPVersion.new("0.9"), req.http_version) - assert_equal(WEBrick::Config::HTTP[:ServerName], req.host) + assert_equal(HTTP_CONFIG[:ServerName], req.host) assert_equal(80, req.port) assert_equal(false, req.keep_alive?) assert_equal(nil, req.body) @@ -25,12 +27,12 @@ GET / HTTP/1.0 _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) assert_equal("GET", req.request_method) assert_equal("/", req.unparsed_uri) assert_equal(WEBrick::HTTPVersion.new("1.0"), req.http_version) - assert_equal(WEBrick::Config::HTTP[:ServerName], req.host) + assert_equal(HTTP_CONFIG[:ServerName], req.host) assert_equal(80, req.port) assert_equal(false, req.keep_alive?) assert_equal(nil, req.body) @@ -42,14 +44,14 @@ GET /path HTTP/1.1 _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) assert_equal("GET", req.request_method) assert_equal("/path", req.unparsed_uri) assert_equal("", req.script_name) assert_equal("/path", req.path_info) assert_equal(WEBrick::HTTPVersion.new("1.1"), req.http_version) - assert_equal(WEBrick::Config::HTTP[:ServerName], req.host) + assert_equal(HTTP_CONFIG[:ServerName], req.host) assert_equal(80, req.port) assert_equal(true, req.keep_alive?) assert_equal(nil, req.body) @@ -60,7 +62,7 @@ msg = <<-_end_of_message_ GET /#{"a"*2084} HTTP/1.1 _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) assert_raise(WEBrick::HTTPStatus::RequestURITooLarge){ req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) } @@ -83,7 +85,7 @@ foobar _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) assert_equal( URI.parse("http://test.ruby-lang.org:8080/path"), req.request_uri) @@ -113,7 +115,7 @@ hogehoge _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) assert_equal("POST", req.request_method) assert_equal("/foo/baz", req.path) @@ -130,7 +132,7 @@ Host: test.ruby-lang.org _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) assert_equal(URI.parse("http://test.ruby-lang.org/path"), req.request_uri) assert_equal("test.ruby-lang.org", req.host) @@ -141,7 +143,7 @@ Host: 192.168.1.1 _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) assert_equal(URI.parse("http://192.168.1.1/path"), req.request_uri) assert_equal("192.168.1.1", req.host) @@ -152,7 +154,7 @@ Host: [fe80::208:dff:feef:98c7] _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) assert_equal(URI.parse("http://[fe80::208:dff:feef:98c7]/path"), req.request_uri) @@ -164,7 +166,7 @@ Host: 192.168.1.1:8080 _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) assert_equal(URI.parse("http://192.168.1.1:8080/path"), req.request_uri) assert_equal("192.168.1.1", req.host) @@ -175,7 +177,7 @@ Host: [fe80::208:dff:feef:98c7]:8080 _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) assert_equal(URI.parse("http://[fe80::208:dff:feef:98c7]:8080/path"), req.request_uri) @@ -190,7 +192,7 @@ Host: test.ruby-lang.org:8080 _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) query = req.query assert_equal("1", query["foo"]) @@ -210,7 +212,7 @@ #{param} _end_of_message_ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) query = req.query assert_equal("1", query["foo"]) @@ -236,7 +238,7 @@ end } msg << "0" << crlf - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg)) assert_equal(File.read(__FILE__), req.body) end @@ -253,7 +255,7 @@ _end_of_message_ msg.gsub!(/^ {6}/, "") - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg)) assert_equal("server.example.com", req.server_name) assert_equal("http://forward.example.com/foo", req.request_uri.to_s) @@ -273,7 +275,7 @@ _end_of_message_ msg.gsub!(/^ {6}/, "") - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg)) assert_equal("server.example.com", req.server_name) assert_equal("http://forward.example.com:8080/foo", req.request_uri.to_s) @@ -295,7 +297,7 @@ _end_of_message_ msg.gsub!(/^ {6}/, "") - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg)) assert_equal("server.example.com", req.server_name) assert_equal("https://forward.example.com/foo", req.request_uri.to_s) @@ -312,7 +314,7 @@ _end_of_message_ msg.gsub!(/^ {6}/, "") - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg)) assert req['expect'] l = msg.size @@ -328,7 +330,7 @@ _end_of_message_ msg.gsub!(/^ {6}/, "") - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg)) assert !req['expect'] l = msg.size @@ -346,7 +348,7 @@ #{param} _end_of_message_ assert_raise(WEBrick::HTTPStatus::LengthRequired){ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) req.body } @@ -359,7 +361,7 @@ body is too short. _end_of_message_ assert_raise(WEBrick::HTTPStatus::BadRequest){ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) req.body } @@ -372,7 +374,7 @@ body is too short. _end_of_message_ assert_raise(WEBrick::HTTPStatus::NotImplemented){ - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(StringIO.new(msg.gsub(/^ {6}/, ""))) req.body } Index: test/webrick/test_filehandler.rb =================================================================== --- test/webrick/test_filehandler.rb (revision 30049) +++ test/webrick/test_filehandler.rb (working copy) @@ -4,9 +4,11 @@ require "stringio" class WEBrick::TestFileHandler < Test::Unit::TestCase + HTTP_CONFIG = WEBrick::Config::HTTP.merge(:ServerName => 'localhost') + def default_file_handler(filename) klass = WEBrick::HTTPServlet::DefaultFileHandler - klass.new(WEBrick::Config::HTTP, filename) + klass.new(HTTP_CONFIG, filename) end def windows? @@ -31,9 +33,9 @@ end def make_range_response(file, range_spec) - req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req = WEBrick::HTTPRequest.new(HTTP_CONFIG) req.parse(make_range_request(range_spec)) - res = WEBrick::HTTPResponse.new(WEBrick::Config::HTTP) + res = WEBrick::HTTPResponse.new(HTTP_CONFIG) size = File.size(file) handler = default_file_handler(file) handler.make_partial_content(req, res, file, size)