unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob 5f3b16d7c4b44c00ce157ae3a976554e5efea0ab 1364 bytes (raw)
$ git show v0.9.2:test/unit/test_trailer_parser.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
require 'test/unit'
require 'unicorn'
require 'unicorn_http'
require 'unicorn/trailer_parser'

class TestTrailerParser < Test::Unit::TestCase

  def test_basic
    tp = Unicorn::TrailerParser.new('Content-MD5')
    env = {}
    assert ! tp.execute!(env, "Content-MD5: asdf")
    assert env.empty?
    assert tp.execute!(env, "Content-MD5: asdf\r\n")
    assert_equal 'asdf', env['HTTP_CONTENT_MD5']
    assert_equal 1, env.size
  end

  def test_invalid_trailer
    tp = Unicorn::TrailerParser.new('Content-MD5')
    env = {}
    assert_raises(Unicorn::HttpParserError) {
      tp.execute!(env, "Content-MD: asdf\r\n")
    }
    assert env.empty?
  end

  def test_multiple_trailer
    tp = Unicorn::TrailerParser.new('Foo,Bar')
    env = {}
    buf = "Bar: a\r\nFoo: b\r\n"
    assert tp.execute!(env, buf)
    assert_equal 'a', env['HTTP_BAR']
    assert_equal 'b', env['HTTP_FOO']
  end

  def test_too_big_key
    tp = Unicorn::TrailerParser.new('Foo,Bar')
    env = {}
    buf = "Bar#{'a' * 1024}: a\r\nFoo: b\r\n"
    assert_raises(Unicorn::HttpParserError) { tp.execute!(env, buf) }
    assert env.empty?
  end

  def test_too_big_value
    tp = Unicorn::TrailerParser.new('Foo,Bar')
    env = {}
    buf = "Bar: #{'a' * (1024 * 1024)}: a\r\nFoo: b\r\n"
    assert_raises(Unicorn::HttpParserError) { tp.execute!(env, buf) }
    assert env.empty?
  end

end

git clone https://yhbt.net/unicorn.git