Skip to content

Commit ee6bfcf

Browse files
authored
Merge pull request #175 from rivques/main
Close #174 by sending entire webserver response to ESP32 in one go if possible
2 parents 7d3e873 + c50a103 commit ee6bfcf

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

adafruit_esp32spi/adafruit_esp32spi_wsgiserver.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ def finish_response(self, result):
119119
response += "{0}: {1}\r\n".format(*header)
120120
response += "\r\n"
121121
self._client_sock.send(response.encode("utf-8"))
122-
for data in result:
123-
if isinstance(data, bytes):
124-
self._client_sock.send(data)
125-
else:
126-
self._client_sock.send(data.encode("utf-8"))
122+
if isinstance(result, bytes): # send whole response if possible (see #174)
123+
self._client_sock.send(result)
124+
elif isinstance(result, str):
125+
self._client_sock.send(result.encode("utf-8"))
126+
else: # fall back to sending byte-by-byte
127+
for data in result:
128+
if isinstance(data, bytes):
129+
self._client_sock.send(data)
130+
else:
131+
self._client_sock.send(data.encode("utf-8"))
127132
gc.collect()
128133
finally:
129134
if self._debug > 2:

0 commit comments

Comments
 (0)