Skip to content

Commit 4e63771

Browse files
authored
Expose buffer_size in response.send_file, adjust default to match the one in server
1 parent 90c2801 commit 4e63771

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
@@ -172,6 +172,7 @@ def poll(self):
172172
HTTPResponse(request).send_file(
173173
filename=request.path,
174174
root_path=self.root_path,
175+
buffer_size=self.request_buffer_size,
175176
)
176177
else:
177178
HTTPResponse(

0 commit comments

Comments
 (0)