summaryrefslogtreecommitdiffstats
path: root/test/modules/http2/test_202_trailer.py
blob: ae3d8970b3f4482bfaeda5304d1d7d5b54fa63fc (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import pytest

from .env import H2Conf


def setup_data(env):
    s100 = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n"
    with open(os.path.join(env.gen_dir, "data-1k"), 'w') as f:
        for i in range(10):
            f.write(s100)


# The trailer tests depend on "nghttp" as no other client seems to be able to send those
# rare things.
class TestTrailers:

    @pytest.fixture(autouse=True, scope='class')
    def _class_scope(self, env):
        setup_data(env)
        H2Conf(env).add_vhost_cgi(h2proxy_self=True).install()
        assert env.apache_restart() == 0

    # check if the server survives a trailer or two
    def test_h2_202_01(self, env):
        url = env.mkurl("https", "cgi", "/echo.py")
        fpath = os.path.join(env.gen_dir, "data-1k")
        r = env.nghttp().upload(url, fpath, options=["--trailer", "test: 1"])
        assert r.response["status"] < 300
        assert len(r.response["body"]) == 1000

        r = env.nghttp().upload(url, fpath, options=["--trailer", "test: 1b", "--trailer", "XXX: test"])
        assert r.response["status"] < 300
        assert len(r.response["body"]) == 1000

    # check if the server survives a trailer without content-length
    def test_h2_202_02(self, env):
        url = env.mkurl("https", "cgi", "/echo.py")
        fpath = os.path.join(env.gen_dir, "data-1k")
        r = env.nghttp().upload(url, fpath, options=["--trailer", "test: 2", "--no-content-length"])
        assert r.response["status"] < 300
        assert len(r.response["body"]) == 1000

    # check if echoing request headers in response from GET works
    def test_h2_202_03(self, env):
        url = env.mkurl("https", "cgi", "/echohd.py?name=X")
        r = env.nghttp().get(url, options=["--header", "X: 3"])
        assert r.response["status"] < 300
        assert r.response["body"] == b"X: 3\n"

    # check if echoing request headers in response from POST works
    def test_h2_202_03b(self, env):
        url = env.mkurl("https", "cgi", "/echohd.py?name=X")
        r = env.nghttp().post_name(url, "Y", options=["--header", "X: 3b"])
        assert r.response["status"] < 300
        assert r.response["body"] == b"X: 3b\n"

    # check if echoing request headers in response from POST works, but trailers are not seen
    # This is the way CGI invocation works.
    def test_h2_202_04(self, env):
        url = env.mkurl("https", "cgi", "/echohd.py?name=X")
        r = env.nghttp().post_name(url, "Y", options=["--header", "X: 4a", "--trailer", "X: 4b"])
        assert r.response["status"] < 300
        assert r.response["body"] == b"X: 4a\n"