Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
server_addr = headers["Host"]
if ":" not in server_addr:
server_port = 80
else:
server_port = int(server_addr.split(":")[1])
server = (server_addr, server_port)
scope = {
"server": server,
"client": client,
"scheme": scheme,
"root_path": "",
"query_string": query_string,
"headers": [[maybe_encode(k), maybe_encode(v)] for k, v in headers.items()],
"type": "http",
"http_version": "1.1",
"method": method,
"path": path,
}
binary = event.get("isBase64Encoded", False)
body = event["body"]
if body:
if binary:
body = base64.b64decode(body)
else:
body = maybe_encode(body)
else:
body = b""
"query_string": query_string,
"headers": [[maybe_encode(k), maybe_encode(v)] for k, v in headers.items()],
"type": "http",
"http_version": "1.1",
"method": method,
"path": path,
}
binary = event.get("isBase64Encoded", False)
body = event["body"]
if body:
if binary:
body = base64.b64decode(body)
else:
body = maybe_encode(body)
else:
body = b""
response = AWSLambdaASGICycle(scope, binary=binary)(self.app, body=body)
return response
charset = options.get("charset", None)
if charset:
self.charset = charset
if mimetype:
self.mimetype = mimetype
self.on_response_start(headers, status_code)
self.state = ASGICycleState.RESPONSE
elif self.state is ASGICycleState.RESPONSE:
if message_type != "http.response.body":
raise RuntimeError(
f"Expected 'http.response.body', received: {message_type}"
)
body = maybe_encode(message.get("body", b""))
more_body = message.get("more_body", False)
self.body += body
if not more_body:
self.on_response_close()
self.put_message({"type": "http.disconnect"})
parsed = urllib.parse.urlparse(event.url)
scheme = parsed.scheme
path = parsed.path
query_string = encode_query_string(event.params) if event.params else b""
scope = {
"type": "http",
"server": server,
"client": client,
"method": method,
"path": path,
"scheme": scheme,
"http_version": "1.1",
"root_path": "",
"query_string": query_string,
"headers": [[maybe_encode(k), maybe_encode(v)] for k, v in headers],
}
body = event.get_body() or b""
response = AzureFunctionCycle(scope)(self.app, body=body)
return HttpResponse(
body=response["body"],
headers=response["headers"],
status_code=response["status_code"],
mimetype=response["mimetype"],
charset=response["charset"],
)