MCPcopy
hub / github.com/pallets/werkzeug / set_cookie

Method set_cookie

src/werkzeug/test.py:849–902  ·  view source on GitHub ↗

Set a cookie to be sent in subsequent requests. This is a convenience to skip making a test request to a route that would set the cookie. To test the cookie, make a test request to a route that uses the cookie value. The client uses ``domain``, ``origin_only``, and

(
        self,
        key: str,
        value: str = "",
        *,
        domain: str = "localhost",
        origin_only: bool = True,
        path: str = "/",
        **kwargs: t.Any,
    )

Source from the content-addressed store, hash-verified

847 return self._cookies.get((domain, path, key))
848
849 def set_cookie(
850 self,
851 key: str,
852 value: str = "",
853 *,
854 domain: str = "localhost",
855 origin_only: bool = True,
856 path: str = "/",
857 **kwargs: t.Any,
858 ) -> None:
859 """Set a cookie to be sent in subsequent requests.
860
861 This is a convenience to skip making a test request to a route that would set
862 the cookie. To test the cookie, make a test request to a route that uses the
863 cookie value.
864
865 The client uses ``domain``, ``origin_only``, and ``path`` to determine which
866 cookies to send with a request. It does not use other cookie parameters that
867 browsers use, since they're not applicable in tests.
868
869 :param key: The key part of the cookie.
870 :param value: The value part of the cookie.
871 :param domain: Send this cookie with requests that match this domain. If
872 ``origin_only`` is true, it must be an exact match, otherwise it may be a
873 suffix match.
874 :param origin_only: Whether the domain must be an exact match to the request.
875 :param path: Send this cookie with requests that match this path either exactly
876 or as a prefix.
877 :param kwargs: Passed to :func:`.dump_cookie`.
878
879 .. versionchanged:: 3.0
880 The parameter ``server_name`` is removed. The first parameter is
881 ``key``. Use the ``domain`` and ``origin_only`` parameters instead.
882
883 .. versionchanged:: 2.3
884 The ``origin_only`` parameter was added.
885
886 .. versionchanged:: 2.3
887 The ``domain`` parameter defaults to ``localhost``.
888 """
889 if self._cookies is None:
890 raise TypeError(
891 "Cookies are disabled. Create a client with 'use_cookies=True'."
892 )
893
894 cookie = Cookie._from_response_header(
895 domain, "/", dump_cookie(key, value, domain=domain, path=path, **kwargs)
896 )
897 cookie.origin_only = origin_only
898
899 if cookie._should_delete:
900 self._cookies.pop(cookie._storage_key, None)
901 else:
902 self._cookies[cookie._storage_key] = cookie
903
904 def delete_cookie(
905 self,

Callers 2

test_cookie_forgingFunction · 0.95
appFunction · 0.45

Calls 3

dump_cookieFunction · 0.85
_from_response_headerMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected