summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/resource-timing/resources/header-delay.py
blob: 631f7855f86bb64df6e84306de0ed5562d913f56 (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
from time import sleep

def main(request, response):
    delay = int(request.GET.first(b"delay")) / 1000

    # TODO: make this exported from ResponseWriter
    handler = response.writer._handler
    if b"with100" in request.GET:
        sleep(delay)
        handler.send_response(100)
        handler.end_headers()

    if b"with103" in request.GET:
        sleep(delay)
        handler.send_response(103)
        handler.send_header("Link", "<resources/empty.js>;rel=preload;as=script")
        handler.end_headers()

    sleep(delay)

    handler.send_response(200)

    if b"tao" in request.GET:
        handler.send_header("timing-allow-origin", "*")

    handler.send_header("content-type", "text/plain")
    handler.send_header("access-control-allow-origin", "*")
    handler.end_headers()
    handler.wfile.write(bytes("Hello World", "utf8"))