summaryrefslogtreecommitdiffstats
path: root/test/modules/http2/test_201_header_conditional.py
blob: f1032683bf4ee85f497b9e4b4f10f01ea782a6ae (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
66
67
68
69
70
import pytest

from .env import H2Conf, H2TestEnv


@pytest.mark.skipif(condition=H2TestEnv.is_unsupported, reason="mod_http2 not supported here")
class TestConditionalHeaders:

    @pytest.fixture(autouse=True, scope='class')
    def _class_scope(self, env):
        H2Conf(env).add(
            """
            KeepAlive on
            MaxKeepAliveRequests 30
            KeepAliveTimeout 30"""
        ).add_vhost_test1().install()
        assert env.apache_restart() == 0

    # check handling of 'if-modified-since' header
    def test_h2_201_01(self, env):
        url = env.mkurl("https", "test1", "/006/006.css")
        r = env.curl_get(url)
        assert r.response["status"] == 200
        lm = r.response["header"]["last-modified"]
        assert lm
        r = env.curl_get(url, options=["-H", "if-modified-since: %s" % lm])
        assert 304 == r.response["status"]
        r = env.curl_get(url, options=["-H", "if-modified-since: Tue, 04 Sep 2010 11:51:59 GMT"])
        assert r.response["status"] == 200

    # check handling of 'if-none-match' header
    def test_h2_201_02(self, env):
        url = env.mkurl("https", "test1", "/006/006.css")
        r = env.curl_get(url)
        assert r.response["status"] == 200
        etag = r.response["header"]["etag"]
        assert etag
        r = env.curl_get(url, options=["-H", "if-none-match: %s" % etag])
        assert 304 == r.response["status"]
        r = env.curl_get(url, options=["-H", "if-none-match: dummy"])
        assert r.response["status"] == 200
        
    @pytest.mark.skipif(True, reason="304 misses the Vary header in trunk and 2.4.x")
    def test_h2_201_03(self, env):
        url = env.mkurl("https", "test1", "/006.html")
        r = env.curl_get(url, options=["-H", "Accept-Encoding: gzip"])
        assert r.response["status"] == 200
        for h in r.response["header"]:
            print("%s: %s" % (h, r.response["header"][h]))
        lm = r.response["header"]["last-modified"]
        assert lm
        assert "gzip" == r.response["header"]["content-encoding"]
        assert "Accept-Encoding" in r.response["header"]["vary"]
        
        r = env.curl_get(url, options=["-H", "if-modified-since: %s" % lm,
                                       "-H", "Accept-Encoding: gzip"])
        assert 304 == r.response["status"]
        for h in r.response["header"]:
            print("%s: %s" % (h, r.response["header"][h]))
        assert "vary" in r.response["header"]

    # Check if "Keep-Alive" response header is removed in HTTP/2.
    def test_h2_201_04(self, env):
        url = env.mkurl("https", "test1", "/006.html")
        r = env.curl_get(url, options=["--http1.1", "-H", "Connection: keep-alive"])
        assert r.response["status"] == 200
        assert "timeout=30, max=30" == r.response["header"]["keep-alive"]
        r = env.curl_get(url, options=["-H", "Connection: keep-alive"])
        assert r.response["status"] == 200
        assert "keep-alive" not in r.response["header"]