Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions azure/functions/_http_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ def _get_server_address(self):
return None

def to_asgi_http_scope(self):
if self.path_info is not None:
_raw_path = self.path_info.encode("utf-8")
else:
_raw_path = b''
if self.query_string is not None:
_query_string = self.query_string.encode("utf-8")
else:
_query_string = b''

return {
"type": "http",
"asgi.version": self.asgi_version,
Expand All @@ -37,8 +46,8 @@ def to_asgi_http_scope(self):
"method": self.request_method,
"scheme": "https",
"path": self.path_info,
"raw_path": self.path_info.encode("utf-8"),
"query_string": self.query_string.encode("utf-8"), # type: ignore
"raw_path": _raw_path,
"query_string": _query_string,
"root_path": self.script_name,
"headers": self._get_encoded_http_headers(),
"server": self._get_server_address(),
Expand All @@ -57,7 +66,7 @@ def __init__(self):
self._status_code = 0
self._headers: Union[Headers, Dict] = {}
self._buffer: List[bytes] = []
self._request_body = b""
self._request_body: Optional[bytes] = b""

@classmethod
async def from_app(cls, app, scope: Dict[str, Any],
Expand Down Expand Up @@ -89,11 +98,18 @@ def _handle_http_response_body(self, message: Dict[str, Any]):
# https://github.com/Azure/azure-functions-host/issues/4926

async def _receive(self):
return {
"type": "http.request",
"body": self._request_body,
"more_body": False,
}
if self._request_body is not None:
reply = {
"type": "http.request",
"body": self._request_body,
"more_body": False,
}
self._request_body = None
else:
reply = {
"type": "http.disconnect",
}
return reply

async def _send(self, message):
logging.debug(f"Received {message} from ASGI worker.")
Expand Down
3 changes: 3 additions & 0 deletions tests/test_http_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ async def __call__(self, scope, receive, send):
assert isinstance(self.received_request['body'], bytes)
assert isinstance(self.received_request['more_body'], bool)

self.next_request = await receive()
assert self.next_request['type'] == 'http.disconnect'

await send(
{
"type": "http.response.start",
Expand Down