Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import urllib.parse
from azure.functions import HttpRequest, HttpResponse
from mangum.asgi.protocol import ASGICycle
from mangum.asgi.adapter import ServerlessAdapter
from mangum.utils import encode_query_string, maybe_encode
class AzureFunctionCycle(ASGICycle):
"""
An adapter that handles the HTTP request-response cycle for an ASGI application and
builds a valid response to return to Azure Functions.
The response is a Python dictionary with the following structure:
{
"body": bytes,
"charset": str,
"headers": dict,
"mimetype": str,
"status_code": itnt
}
"""
def on_response_start(self, headers: dict, status_code: int) -> None:
import base64
from mangum.utils import encode_query_string, maybe_encode
from mangum.asgi.protocol import ASGICycle
from mangum.asgi.adapter import ServerlessAdapter
class AWSLambdaASGICycle(ASGICycle):
"""
An adapter that handles the HTTP request-response cycle for an ASGI application and
builds a valid response to return to AWS Lambda & API Gateway.
The response is a Python dictionary with the following structure:
{
"statusCode": int,
"isBase64Encoded": bool,
"headers": dict,
"body": str,
}
"""
def __init__(self, *args, **kwargs) -> None:
self.binary = kwargs.pop("binary", False)