~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to test/webrick/test_httprequest.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-05-16 12:37:06 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080516123706-r4llcdfd35aobrjv
Tags: 1.9.0.1-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.
* debian/control:
  - ruby1.9 pkg: moved rdoc1.9 suggestion to depends. (LP: #228345)

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
      Accept-Language: ja
80
80
      Content-Type: text/plain
81
81
      Content-Length: 7
 
82
      X-Empty-Header: 
82
83
 
83
84
      foobar
84
85
    _end_of_message_
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?)
101
104
  end
102
105
 
238
241
    assert_equal(File.read(__FILE__), req.body)
239
242
  end
240
243
 
 
244
  def test_forwarded
 
245
    msg = <<-_end_of_message_
 
246
      GET /foo HTTP/1.1
 
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
 
253
 
 
254
    _end_of_message_
 
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)
 
263
    assert(!req.ssl?)
 
264
 
 
265
    msg = <<-_end_of_message_
 
266
      GET /foo HTTP/1.1
 
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
 
273
 
 
274
    _end_of_message_
 
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)
 
283
    assert(!req.ssl?)
 
284
 
 
285
    msg = <<-_end_of_message_
 
286
      GET /foo HTTP/1.1
 
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
 
295
 
 
296
    _end_of_message_
 
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)
 
305
    assert(req.ssl?)
 
306
  end
 
307
 
241
308
  def test_bad_messages
242
309
    param = "foo=1;foo=2;foo=3;bar=x"
243
310
    msg = <<-_end_of_message_