summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cookies/resources/echo-json.py
blob: 8f82aa1e96ca3c7f2bc5998b07a743207ad95626 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import json

def main(request, response):
    headers = [("Content-Type", "application/json"),
               ("Access-Control-Allow-Credentials", "true")]

    if "origin" in request.headers:
        headers.append(("Access-Control-Allow-Origin", request.headers["origin"]))

    values = []
    for key in request.cookies:
        for value in request.cookies.get_list(key):
            values.append("\"%s\": \"%s\"" % (key, value))
    body = "{ %s }" % ",".join(values)
    return headers, body