Exemplo n.º 1
0
def test_consume_byte_by_byte():
    responder = mock_responder()
    p = Parser(responder)
    for b in "GET / HTTP/1.1\nhost: nowhere.com\n\n":
        p.consume(b.encode())
    assert not p.needs_headers
    assert 'HOST' in responder.headers
    assert responder.headers['HOST'] == "nowhere.com"
Exemplo n.º 2
0
def test_good_header_pieces():
    q = mock_responder()
    p = Parser(q)
    p.consume(b"GET / HTTP/1.1\r\n")
    p.consume(b"host: nowhere.com\r\n")
    p.consume(b"\r\n")
    headers = q.headers
    assert not p.needs_headers
    assert 'HOST' in headers
    assert headers['HOST'] == 'nowhere.com'
Exemplo n.º 3
0
def test_consume():
    q = mock_responder()
    p = Parser(q)
    p.consume(b"GET")
    assert p._buffer == [b"GET"]
    p.consume(b" /path HTTP/1.1")
    p.consume(b"\n")
    data = q.data
    assert data['method'] == 'GET'
    assert data['url'].path == '/path'
    assert data['version'] == 'HTTP/1.1'
    assert not p.needs_request_line

    q2 = mock_responder()
    Parser(q2).consume(b"GET /path HTTP/1.1\nhost: noplace\n\n")
    data = q2.data
    assert data['method'] == 'GET'
    assert data['url'].path == '/path'
    assert data['version'] == 'HTTP/1.1'