Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Firefox/testing/web-platform/tests/cookies/resources/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 1 kB image not shown  

Quelle  cookie.py   Sprache: Python

 
import json

from cookies.resources.helpers import setNoCacheAndCORSHeaders
from wptserve.utils import isomorphic_decode
from wptserve.utils import isomorphic_encode

def set_cookie(headers, cookie_string):
    """Helper method to add a Set-Cookie header"""
    headers.append((b'Set-Cookie', isomorphic_encode(cookie_string)))

def main(request, response):
    """Set a cookie via GET params.

    Usage: `/cookie.py?set={cookie}`

    The passed-in cookie string should be stringified via JSON.stringify() (in
    the case of multiple cookie headers sent in an array) and encoded via
    encodeURIComponent, otherwise `parse_qsl` will split on any semicolons
    (used by the Request.GET property getter). Note that values returned by
    Request.GET will decode any percent-encoded sequences sent in a GET param
    (which may or may not be surprising depending on what you're doing).

    Note: here we don't use Response.delete_cookie() or similar other methods
    in this resources directory because there are edge cases that are impossible
    to express via those APIs, namely a bare (`Path`) or empty Path (`Path=`)
    attribute. Instead, we pipe through the entire cookie and append `max-age=0`
    to it.
    """
    headers = setNoCacheAndCORSHeaders(request, response)

    if b'set' in request.GET:
        cookie = isomorphic_decode(request.GET[b'set'])
        cookie = json.loads(cookie)
        cookies = cookie if isinstance(cookie, list) else [cookie]
        for c in cookies:
            set_cookie(headers, c)

    if b'location' in request.GET:
        headers.append((b'Location', request.GET[b'location']))
        return 302, headers, b'{"redirect": true}'

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

Messung V0.5
C=95 H=98 G=96

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.