Skip to content

Commit 874d3ed

Browse files
authored
Merge pull request #37 from matemaciek/main
Buffer_size improvements
2 parents e349088 + 4e63771 commit 874d3ed

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

adafruit_httpserver/response.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ def send_file(
171171
self,
172172
filename: str = "index.html",
173173
root_path: str = "./",
174+
buffer_size: int = 1024,
174175
) -> None:
175176
"""
176177
Send response with content of ``filename`` located in ``root_path``.
177178
Implicitly calls ``_send_headers`` before sending the file content.
179+
File is send split into ``buffer_size`` parts.
178180
179181
Should be called **only once** per response.
180182
"""
@@ -196,7 +198,7 @@ def send_file(
196198
)
197199

198200
with open(root_path + filename, "rb") as file:
199-
while bytes_read := file.read(2048):
201+
while bytes_read := file.read(buffer_size):
200202
self._send_bytes(self.request.connection, bytes_read)
201203
self._response_already_sent = True
202204

adafruit_httpserver/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def poll(self):
173173
HTTPResponse(request).send_file(
174174
filename=filename,
175175
root_path=self.root_path,
176+
buffer_size=self.request_buffer_size,
176177
)
177178
else:
178179
HTTPResponse(

0 commit comments

Comments
 (0)