Skip to content

Commit f70c524

Browse files
always encode ASGI response bodies to bytes
1 parent 79897e7 commit f70c524

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/microdot/asgi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ async def cancel_monitor():
130130
try:
131131
while not cancelled: # pragma: no branch
132132
res_body = await body_iter.__anext__()
133+
if isinstance(res_body, str):
134+
res_body = res_body.encode()
133135
await send({'type': 'http.response.body',
134136
'body': res_body,
135137
'more_body': True})

tests/test_asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def index(req):
3535
class R:
3636
def __init__(self):
3737
self.i = 0
38-
self.body = [b're', b'sp', b'on', b'se', b'']
38+
self.body = [b're', b'sp', b'on', 'se', b'']
3939

4040
async def read(self, n):
4141
data = self.body[self.i]

0 commit comments

Comments
 (0)