Skip to content

Commit

Permalink
Merge pull request #175 from rivques/main
Browse files Browse the repository at this point in the history
Close #174 by sending entire webserver response to ESP32 in one go if possible
  • Loading branch information
dhalbert committed Sep 11, 2022
2 parents 7d3e873 + c50a103 commit ee6bfcf
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions adafruit_esp32spi/adafruit_esp32spi_wsgiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ def finish_response(self, result):
response += "{0}: {1}\r\n".format(*header)
response += "\r\n"
self._client_sock.send(response.encode("utf-8"))
for data in result:
if isinstance(data, bytes):
self._client_sock.send(data)
else:
self._client_sock.send(data.encode("utf-8"))
if isinstance(result, bytes): # send whole response if possible (see #174)
self._client_sock.send(result)
elif isinstance(result, str):
self._client_sock.send(result.encode("utf-8"))
else: # fall back to sending byte-by-byte
for data in result:
if isinstance(data, bytes):
self._client_sock.send(data)
else:
self._client_sock.send(data.encode("utf-8"))
gc.collect()
finally:
if self._debug > 2:
Expand Down

0 comments on commit ee6bfcf

Please sign in to comment.