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

Method set_cookie

src/werkzeug/sansio/response.py:189–245  ·  view source on GitHub ↗

Sets a cookie. A warning is raised if the size of the cookie header exceeds :attr:`max_cookie_size`, but the header will still be set. :param key: the key (name) of the cookie to be set. :param value: the value of the cookie. :param max_age: should be a numb

(
        self,
        key: str,
        value: str = "",
        max_age: timedelta | int | None = None,
        expires: str | datetime | int | float | None = None,
        path: str | None = "/",
        domain: str | None = None,
        secure: bool = False,
        httponly: bool = False,
        samesite: str | None = None,
        partitioned: bool = False,
    )

Source from the content-addressed store, hash-verified

187 return status, status_code
188
189 def set_cookie(
190 self,
191 key: str,
192 value: str = "",
193 max_age: timedelta | int | None = None,
194 expires: str | datetime | int | float | None = None,
195 path: str | None = "/",
196 domain: str | None = None,
197 secure: bool = False,
198 httponly: bool = False,
199 samesite: str | None = None,
200 partitioned: bool = False,
201 ) -> None:
202 """Sets a cookie.
203
204 A warning is raised if the size of the cookie header exceeds
205 :attr:`max_cookie_size`, but the header will still be set.
206
207 :param key: the key (name) of the cookie to be set.
208 :param value: the value of the cookie.
209 :param max_age: should be a number of seconds, or `None` (default) if
210 the cookie should last only as long as the client's
211 browser session.
212 :param expires: should be a `datetime` object or UNIX timestamp.
213 :param path: limits the cookie to a given path, per default it will
214 span the whole domain.
215 :param domain: if you want to set a cross-domain cookie. For example,
216 ``domain="example.com"`` will set a cookie that is
217 readable by the domain ``www.example.com``,
218 ``foo.example.com`` etc. Otherwise, a cookie will only
219 be readable by the domain that set it.
220 :param secure: If ``True``, the cookie will only be available
221 via HTTPS.
222 :param httponly: Disallow JavaScript access to the cookie.
223 :param samesite: Limit the scope of the cookie to only be
224 attached to requests that are "same-site".
225 :param partitioned: If ``True``, the cookie will be partitioned.
226
227 .. versionchanged:: 3.1
228 The ``partitioned`` parameter was added.
229 """
230 self.headers.add(
231 "Set-Cookie",
232 dump_cookie(
233 key,
234 value=value,
235 max_age=max_age,
236 expires=expires,
237 path=path,
238 domain=domain,
239 secure=secure,
240 httponly=httponly,
241 max_size=self.max_cookie_size,
242 samesite=samesite,
243 partitioned=partitioned,
244 ),
245 )
246

Callers 10

delete_cookieMethod · 0.95
pin_authMethod · 0.95
cookie_appFunction · 0.95
appFunction · 0.95
test_appFunction · 0.95
test_base_responseFunction · 0.95
test_secureMethod · 0.95
test_httponlyMethod · 0.95
test_samesiteMethod · 0.95

Calls 2

dump_cookieFunction · 0.85
addMethod · 0.45

Tested by 8

cookie_appFunction · 0.76
appFunction · 0.76
test_appFunction · 0.76
test_base_responseFunction · 0.76
test_secureMethod · 0.76
test_httponlyMethod · 0.76
test_samesiteMethod · 0.76