forked from nginx/unit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: bytearray body support for ASGI module.
@filiphanes requested support for bytearray and memoryview in the request body here: nginx#648 This patch implements bytearray body support only. Memoryview body still need to be implemented.
- Loading branch information
1 parent
990fbe7
commit 69107e6
Showing
4 changed files
with
53 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
async def application(scope, receive, send): | ||
assert scope['type'] == 'http' | ||
|
||
body = b'' | ||
while True: | ||
m = await receive() | ||
body += m.get('body', b'') | ||
if not m.get('more_body', False): | ||
body = bytearray(body) | ||
break | ||
|
||
await send( | ||
{ | ||
'type': 'http.response.start', | ||
'status': 200, | ||
'headers': [(b'content-length', str(len(body)).encode())], | ||
} | ||
) | ||
|
||
await send({'type': 'http.response.body', 'body': body}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters