summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cors/resources/cors-cookie.py
blob: 76fa6c165ba64e99a5cf7580e802ccb0befee261 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

def main(request, response):
    origin = request.GET.first("origin", request.headers["origin"])
    credentials = request.GET.first("credentials", "true")

    headers = [("Content-Type", "text/plain")]
    if origin != 'none':
        headers.append(("Access-Control-Allow-Origin", origin))
    if credentials != 'none':
        headers.append(("Access-Control-Allow-Credentials", credentials))

    ident = request.GET.first('ident', 'test')

    if ident in request.cookies:
        body = request.cookies[ident].value
        response.delete_cookie(ident)
    else:
        response.set_cookie(ident, "COOKIE");
        body = "NO_COOKIE"

    return headers, body