2017-05-12 15:16:55 -04:00
|
|
|
require_relative "helper"
|
2011-10-03 16:31:17 -04:00
|
|
|
|
2016-11-22 10:05:49 -05:00
|
|
|
require "puma/puma_http11"
|
2011-10-03 16:31:17 -04:00
|
|
|
|
2016-11-22 10:05:49 -05:00
|
|
|
class Http10ParserTest < Minitest::Test
|
2011-10-03 16:31:17 -04:00
|
|
|
def test_parse_simple
|
2016-11-22 10:05:49 -05:00
|
|
|
parser = Puma::HttpParser.new
|
2011-10-03 16:31:17 -04:00
|
|
|
req = {}
|
|
|
|
http = "GET / HTTP/1.0\r\n\r\n"
|
|
|
|
nread = parser.execute(req, http, 0)
|
|
|
|
|
|
|
|
assert nread == http.length, "Failed to parse the full HTTP request"
|
|
|
|
assert parser.finished?, "Parser didn't finish"
|
|
|
|
assert !parser.error?, "Parser had error"
|
|
|
|
assert nread == parser.nread, "Number read returned from execute does not match"
|
|
|
|
|
|
|
|
assert_equal '/', req['REQUEST_PATH']
|
|
|
|
assert_equal 'HTTP/1.0', req['HTTP_VERSION']
|
|
|
|
assert_equal '/', req['REQUEST_URI']
|
2016-11-22 10:05:49 -05:00
|
|
|
assert_equal 'GET', req['REQUEST_METHOD']
|
2011-10-03 16:31:17 -04:00
|
|
|
assert_nil req['FRAGMENT']
|
|
|
|
assert_nil req['QUERY_STRING']
|
2016-11-22 10:05:49 -05:00
|
|
|
|
2011-10-03 16:31:17 -04:00
|
|
|
parser.reset
|
|
|
|
assert parser.nread == 0, "Number read after reset should be 0"
|
|
|
|
end
|
|
|
|
end
|