File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -155,7 +155,10 @@ def send(
155
155
if self ._response_already_sent :
156
156
raise RuntimeError ("Response was already sent" )
157
157
158
- encoded_response_message_body = body .encode ("utf-8" )
158
+ if getattr (body , "encode" , None ):
159
+ encoded_response_message_body = body .encode ("utf-8" )
160
+ else :
161
+ encoded_response_message_body = body
159
162
160
163
self ._send_headers (
161
164
content_type = content_type or self .content_type ,
@@ -206,11 +209,12 @@ def send_chunk(self, chunk: str = "") -> None:
206
209
207
210
:param str chunk: String data to be sent.
208
211
"""
209
- hex_length = hex (len (chunk ))[2 :] # removing 0x
212
+ if getattr (chunk , "encode" , None ):
213
+ chunk = chunk .encode ("utf-8" )
210
214
211
- self ._send_bytes (
212
- self .request .connection , f" { hex_length } \r \n { chunk } \r \n " . encode ( "utf-8" )
213
- )
215
+ self ._send_bytes (self . request . connection , b"%x \r \n " % len ( chunk ))
216
+ self ._send_bytes ( self . request .connection , chunk )
217
+ self . _send_bytes ( self . request . connection , b" \r \n " )
214
218
215
219
def __enter__ (self ):
216
220
if self .chunked :
You can’t perform that action at this time.
0 commit comments