File: test_005_trailers.py

package info (click to toggle)
apache2 2.4.66-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 59,228 kB
  • sloc: ansic: 212,321; python: 13,830; perl: 11,308; sh: 6,973; php: 1,320; javascript: 1,314; awk: 749; makefile: 712; lex: 374; yacc: 161; xml: 2
file content (42 lines) | stat: -rw-r--r-- 1,825 bytes parent folder | download | duplicates (4)
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
import os
import pytest

from .env import H1Conf


# 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):
        H1Conf(env).add_vhost_cgi(proxy_self=True).install()
        assert env.apache_restart() == 0

    # check that we get a trailer out when telling the handler to add one
    def test_h1_005_01(self, env):
        if not env.httpd_is_at_least("2.5.0"):
            pytest.skip(f'need at least httpd 2.5.0 for this')
        url = env.mkurl("https", "cgi", "/h1test/echo")
        host = f"cgi.{env.http_tld}"
        fpath = os.path.join(env.gen_dir, "data-1k")
        r = env.curl_upload(url, fpath, options=["--header", "Add-Trailer: 005_01"])
        assert r.exit_code == 0, f"{r}"
        assert 200 <= r.response["status"] < 300
        assert r.response["trailer"], f"no trailers received: {r}"
        assert "h1test-add-trailer" in r.response["trailer"]
        assert r.response["trailer"]["h1test-add-trailer"] == "005_01"

    # check that we get out trailers through the proxy
    def test_h1_005_02(self, env):
        if not env.httpd_is_at_least("2.5.0"):
            pytest.skip(f'need at least httpd 2.5.0 for this')
        url = env.mkurl("https", "cgi", "/proxy/h1test/echo")
        host = f"cgi.{env.http_tld}"
        fpath = os.path.join(env.gen_dir, "data-1k")
        r = env.curl_upload(url, fpath, options=["--header", "Add-Trailer: 005_01"])
        assert r.exit_code == 0, f"{r}"
        assert 200 <= r.response["status"] < 300
        assert r.response["trailer"], f"no trailers received: {r}"
        assert "h1test-add-trailer" in r.response["trailer"]
        assert r.response["trailer"]["h1test-add-trailer"] == "005_01"