97
98
assert_equal(7, req.content_length)
98
99
assert_equal("text/plain", req.content_type)
99
100
assert_equal("foobar\n", req.body)
101
assert_equal("", req["x-empty-header"])
102
assert_equal(nil, req["x-no-header"])
100
103
assert(req.query.empty?)
238
241
assert_equal(File.read(__FILE__), req.body)
245
msg = <<-_end_of_message_
247
Host: localhost:10080
248
User-Agent: w3m/0.5.2
249
X-Forwarded-For: 123.123.123.123
250
X-Forwarded-Host: forward.example.com
251
X-Forwarded-Server: server.example.com
252
Connection: Keep-Alive
255
msg.gsub!(/^ {6}/, "")
256
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
257
req.parse(StringIO.new(msg))
258
assert_equal("server.example.com", req.server_name)
259
assert_equal("http://forward.example.com/foo", req.request_uri.to_s)
260
assert_equal("forward.example.com", req.host)
261
assert_equal(80, req.port)
262
assert_equal("123.123.123.123", req.remote_ip)
265
msg = <<-_end_of_message_
267
Host: localhost:10080
268
User-Agent: w3m/0.5.2
269
X-Forwarded-For: 192.168.1.10, 172.16.1.1, 123.123.123.123
270
X-Forwarded-Host: forward.example.com:8080
271
X-Forwarded-Server: server.example.com
272
Connection: Keep-Alive
275
msg.gsub!(/^ {6}/, "")
276
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
277
req.parse(StringIO.new(msg))
278
assert_equal("server.example.com", req.server_name)
279
assert_equal("http://forward.example.com:8080/foo", req.request_uri.to_s)
280
assert_equal("forward.example.com", req.host)
281
assert_equal(8080, req.port)
282
assert_equal("123.123.123.123", req.remote_ip)
285
msg = <<-_end_of_message_
287
Host: localhost:10080
288
Client-IP: 234.234.234.234
289
X-Forwarded-Proto: https
290
X-Forwarded-For: 192.168.1.10, 10.0.0.1, 123.123.123.123
291
X-Forwarded-Host: forward.example.com
292
X-Forwarded-Server: server.example.com
293
X-Requested-With: XMLHttpRequest
294
Connection: Keep-Alive
297
msg.gsub!(/^ {6}/, "")
298
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
299
req.parse(StringIO.new(msg))
300
assert_equal("server.example.com", req.server_name)
301
assert_equal("https://forward.example.com/foo", req.request_uri.to_s)
302
assert_equal("forward.example.com", req.host)
303
assert_equal(443, req.port)
304
assert_equal("234.234.234.234", req.remote_ip)
241
308
def test_bad_messages
242
309
param = "foo=1;foo=2;foo=3;bar=x"
243
310
msg = <<-_end_of_message_