summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/api/resources/cache.py
blob: 4de751e30bfc6a5f6a8b02cd3ed47aa666d193e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ETAG = b'"123abc"'
CONTENT_TYPE = b"text/plain"
CONTENT = b"lorem ipsum dolor sit amet"


def main(request, response):
    # let caching kick in if possible (conditional GET)
    etag = request.headers.get(b"If-None-Match", None)
    if etag == ETAG:
        response.headers.set(b"X-HTTP-STATUS", 304)
        response.status = (304, b"Not Modified")
        return b""

    # cache miss, so respond with the actual content
    response.status = (200, b"OK")
    response.headers.set(b"ETag", ETAG)
    response.headers.set(b"Content-Type", CONTENT_TYPE)
    return CONTENT