From c39640da3bc22cbf7eb6ea1feaf9cf7ff437db82 Mon Sep 17 00:00:00 2001 From: "mo.asgari" Date: Sat, 12 Mar 2022 22:16:25 +0000 Subject: [PATCH 1/2] send large data in 2kb chunks --- adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py b/adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py index dbdea16..e5d46e2 100644 --- a/adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py +++ b/adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py @@ -124,10 +124,15 @@ def finish_response(self, result, client): response += "\r\n" client.send(response.encode("utf-8")) for data in result: - if isinstance(data, bytes): + if not isinstance(data, bytes): + data = data.encode("utf-8") + if len(data) < 0x800: client.send(data) else: - client.send(data.encode("utf-8")) + # split to chunks of 2 kb + data_chunks = [data[i:i + 0x800] for i in range(0, len(data), 0x800)] + for data_chunk in data_chunks: + client.send(data_chunk) gc.collect() finally: client.disconnect() From a713177db200d3e972d68b4092b2ff4f6469637d Mon Sep 17 00:00:00 2001 From: "mo.asgari" Date: Sun, 13 Mar 2022 08:24:08 +0000 Subject: [PATCH 2/2] reformat code using black/pre-commit --- adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py b/adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py index e5d46e2..46088bb 100644 --- a/adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py +++ b/adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py @@ -130,7 +130,9 @@ def finish_response(self, result, client): client.send(data) else: # split to chunks of 2 kb - data_chunks = [data[i:i + 0x800] for i in range(0, len(data), 0x800)] + data_chunks = [ + data[i : i + 0x800] for i in range(0, len(data), 0x800) + ] for data_chunk in data_chunks: client.send(data_chunk) gc.collect()