I created a azure HTTP triggered function app using python which accepts request and return response based on the request parameters. Now I want read the cookies from the request. How to read the cookie from request?
1
votes
1 Answers
1
votes
You would just have to load/parse the Cookie header from the req object using http.cookies.SimpleCookie
from http.cookies import SimpleCookie
import azure.functions as func
import logging
def main(req: func.HttpRequest) -> func.HttpResponse:
cookie = SimpleCookie()
cookie.load(req.headers['Cookie'])
return func.HttpResponse(f"{cookie['username'].value}")
To test this code, send a request with header like this
Cookie: username=oreo