Bug 1676833 [wpt PR 26500] - Remove ResponseWriter.flush() and explicit_flush, a...
[gecko.git] / testing / web-platform / tests / element-timing / resources / progressive-image.py
blob84e98c84510622c26002ec2bfa593b015ac939a1
1 import os.path
2 import time
4 from wptserve.utils import isomorphic_encode
6 def main(request, response):
7 name = request.GET.first(b"name")
8 sleepTime = float(request.GET.first(b"sleep")) / 1E3
9 numInitial = int(request.GET.first(b"numInitial"))
11 path = os.path.join(os.path.dirname(isomorphic_encode(__file__)), name)
12 body = open(path, u"rb").read()
14 response.headers.set(b"Content-Type", b"image")
15 response.headers.set(b"Content-Length", len(body))
16 response.headers.set(b"Cache-control", b"no-cache, must-revalidate")
17 response.write_status_headers()
19 # Read from the beginning, |numInitial| bytes.
20 first = body[:numInitial]
21 response.writer.write_content(first)
23 time.sleep(sleepTime)
25 # Read the remainder after having slept.
26 second = body[numInitial:]
27 response.writer.write_content(second)