summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/cookies/resources/set.py
blob: eda9338c9269e9c5caf30114adb0ca2ef165e805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from cookies.resources import helpers
from urllib.parse import unquote

from wptserve.utils import isomorphic_encode

def main(request, response):
    """Respond to `/cookie/set?{cookie}` by echoing `{cookie}` as a `Set-Cookie` header."""
    headers = helpers.setNoCacheAndCORSHeaders(request, response)

    # Cookies may require whitespace (e.g. in the `Expires` attribute), so the
    # query string should be decoded.
    cookie = unquote(request.url_parts.query)
    headers.append((b"Set-Cookie", isomorphic_encode(cookie)))

    return headers, b'{"success": true}'