summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/resources/multipart-image.py
blob: 9a3c035f492d9019ad23aaaf94409818ebae9d18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# A request handler that serves a multipart image.

import os


BOUNDARY = b'cutHere'


def create_part(path):
    with open(path, u'rb') as f:
        return b'Content-Type: image/png\r\n\r\n' + f.read() + b'--%s' % BOUNDARY


def main(request, response):
    content_type = b'multipart/x-mixed-replace; boundary=%s' % BOUNDARY
    headers = [(b'Content-Type', content_type)]
    if b'approvecors' in request.GET:
        headers.append((b'Access-Control-Allow-Origin', b'*'))

    image_path = os.path.join(request.doc_root, u'images')
    body = create_part(os.path.join(image_path, u'red.png'))
    body = body + create_part(os.path.join(image_path, u'red-16x16.png'))
    return headers, body