summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cors/resources/status.py
blob: 8d441f06e7cbbef38062485eeff19f7016070456 (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
30
31
32
33
34
35
36
37
def main(request, response):
    response.headers.set("Access-Control-Allow-Origin", request.headers.get("origin") )
    response.headers.set("Access-Control-Expose-Headers", "X-Request-Method")

    if request.method == 'OPTIONS':
        response.headers.set("Access-Control-Allow-Methods",  "GET, CHICKEN, HEAD, POST, PUT")

    if 'headers' in request.GET:
        response.headers.set("Access-Control-Allow-Headers",  request.GET.first('headers'))

    response.headers.set("X-Request-Method", request.method)

    response.headers.set("X-A-C-Request-Method", request.headers.get("Access-Control-Request-Method", ""));


    #This should reasonably work for most response codes.
    try:
        code = int(request.GET.first("code", 200))
    except ValueError:
        code = 200

    text = request.GET.first("text", "OMG")

    if request.method == "OPTIONS" and "preflight" in request.GET:
        try:
            code = int(request.GET.first('preflight'))
        except KeyError, ValueError:
            pass

    status = code, text

    if "type" in request.GET:
        response.headers.set("Content-Type", request.GET.first('type'))

    body = request.GET.first('content', "")

    return status, [], body