cookie.py (765B)
1 def main(request, response): 2 """ 3 Returns a response with a Set-Cookie header based on the query params. 4 The body will be "1" if the cookie is present in the request and `drop` parameter is "0", 5 otherwise the body will be "0". 6 """ 7 same_site = request.GET.first(b"same-site") 8 cookie_name = request.GET.first(b"cookie-name") 9 drop = request.GET.first(b"drop") 10 cookie_in_request = b"0" 11 cookie = b"%s=1; Secure; SameSite=%s" % (cookie_name, same_site) 12 13 if drop == b"1": 14 cookie += b"; Max-Age=0" 15 16 if request.cookies.get(cookie_name): 17 cookie_in_request = request.cookies[cookie_name].value 18 19 headers = [(b'Content-Type', b'text/html'), (b'Set-Cookie', cookie)] 20 return (200, headers, cookie_in_request)