summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/preload/resources/echo-preload-header.py
blob: 5cfb9e8c259a05d0b4646c49bea449b4244ae3b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import os
from wptserve.utils import isomorphic_encode

def main(request, response):
    response.headers.set(b"Content-Type", request.GET.first(b"type"))
    link = request.GET.first(b"link")
    response.headers.set(b"Access-Control-Allow-Origin", b"*")
    response.headers.set(b"Access-Control-Allow-Credentials", b"true")
    if link is not None:
        response.headers.set(b"Link", link)

    if b"file" in request.GET:
        path = os.path.join(os.path.dirname(isomorphic_encode(__file__)), request.GET.first(b"file"));
        response.content = open(path, mode=u'rb').read();
    else:
        return request.GET.first(b"content")