MCPcopy Create free account
hub / github.com/apify/crawlee-python / set_cookies

Function set_cookies

tests/unit/server.py:152–174  ·  view source on GitHub ↗

Handle requests to set cookies from query parameters and redirect.

(scope: dict[str, Any], _receive: Receive, send: Send)

Source from the content-addressed store, hash-verified

150
151
152async def set_cookies(scope: dict[str, Any], _receive: Receive, send: Send) -> None:
153 """Handle requests to set cookies from query parameters and redirect."""
154
155 query_params = get_query_params(scope.get('query_string', b''))
156
157 headers = [
158 [b'content-type', b'text/plain; charset=utf-8'],
159 [b'location', b'/cookies'], # Redirect header
160 ]
161
162 for key, values in query_params.items():
163 if values: # Only add if there's at least one value
164 cookie_value = f'{key}={values[0]}; Path=/'
165 headers.append([b'set-cookie', cookie_value.encode()])
166
167 await send(
168 {
169 'type': 'http.response.start',
170 'status': 302, # 302 Found for redirect
171 'headers': headers,
172 }
173 )
174 await send({'type': 'http.response.body', 'body': b'Redirecting to get_cookies...'})
175
176
177async def hello_world(_scope: dict[str, Any], _receive: Receive, send: Send) -> None:

Callers

nothing calls this directly

Calls 2

get_query_paramsFunction · 0.85
itemsMethod · 0.80

Tested by

no test coverage detected