1
votes

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
Is this using Azure Functions V1 or V2? The python support is very different (and improved) in V2. - Connor McMahon
Yes. I'm using version 2. @ConnorMcMahon. - Karthik Subramaniyam

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