| | 133 | def test_host_port_parsing |
|---|
| | 134 | parser = HttpParser.new |
|---|
| | 135 | req = {} |
|---|
| | 136 | should_be_good = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" |
|---|
| | 137 | nread = parser.execute(req, should_be_good, 0) |
|---|
| | 138 | assert_equal should_be_good.length, nread |
|---|
| | 139 | assert parser.finished? |
|---|
| | 140 | assert !parser.error? |
|---|
| | 141 | assert_equal "example.com", req["HTTP_HOST"] |
|---|
| | 142 | assert_equal "example.com", req["SERVER_NAME"] |
|---|
| | 143 | assert_equal "80", req["SERVER_PORT"] |
|---|
| | 144 | |
|---|
| | 145 | parser = HttpParser.new |
|---|
| | 146 | req = {} |
|---|
| | 147 | should_be_good = "GET / HTTP/1.1\r\nHost: example.com:123\r\n\r\n" |
|---|
| | 148 | nread = parser.execute(req, should_be_good, 0) |
|---|
| | 149 | assert_equal should_be_good.length, nread |
|---|
| | 150 | assert parser.finished? |
|---|
| | 151 | assert !parser.error? |
|---|
| | 152 | assert_equal "example.com:123", req["HTTP_HOST"] |
|---|
| | 153 | assert_equal "example.com", req["SERVER_NAME"] |
|---|
| | 154 | assert_equal "123", req["SERVER_PORT"] |
|---|
| | 155 | |
|---|
| | 156 | # null character in domain name is never actually valid, but if it |
|---|
| | 157 | # becomes valid in Web 3.0, we'll be ready for it. |
|---|
| | 158 | parser = HttpParser.new |
|---|
| | 159 | req = {} |
|---|
| | 160 | should_be_good = "GET / HTTP/1.1\r\nHost: example.com\0:123\r\n\r\n" |
|---|
| | 161 | nread = parser.execute(req, should_be_good, 0) |
|---|
| | 162 | assert_equal should_be_good.length, nread |
|---|
| | 163 | assert parser.finished? |
|---|
| | 164 | assert !parser.error? |
|---|
| | 165 | assert_equal "example.com\0:123", req["HTTP_HOST"] |
|---|
| | 166 | assert_equal "example.com\0", req["SERVER_NAME"] |
|---|
| | 167 | assert_equal "123", req["SERVER_PORT"] |
|---|
| | 168 | end |
|---|
| | 169 | |
|---|