summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fenced-frame/resources/download-stash.py
blob: 497f7cb0187dd4a6382bb25a20a8f76ed3a285f1 (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
import time


def main(request, response):
    token = request.GET[b"token"]
    response.status = 200
    response.headers.append(b"Content-Type", b"text/html")
    if b"verify-token" in request.GET:
        if request.server.stash.take(token):
            return u'TOKEN_SET'
        return u'TOKEN_NOT_SET'

    if b"finish-delay" not in request.GET:
        # <a download>
        request.server.stash.put(token, True)
        return

    # navigation to download
    response.headers.append(b"Content-Disposition", b"attachment")
    response.write_status_headers()
    finish_delay = float(request.GET[b"finish-delay"]) / 1E3
    count = 10
    single_delay = finish_delay / count
    for i in range(count):  # pylint: disable=unused-variable
        time.sleep(single_delay)
        if not response.writer.write_content(b"\n"):
            return
    request.server.stash.put(token, True)