Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion adafruit_httpserver/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,12 @@ def send_file(
self,
filename: str = "index.html",
root_path: str = "./",
buffer_size: int = 2048,
) -> None:
"""
Send response with content of ``filename`` located in ``root_path``.
Implicitly calls ``_send_headers`` before sending the file content.
File is send split into ``buffer_size`` parts.

Should be called **only once** per response.
"""
Expand All @@ -196,7 +198,7 @@ def send_file(
)

with open(root_path + filename, "rb") as file:
while bytes_read := file.read(2048):
while bytes_read := file.read(buffer_size):
self._send_bytes(self.request.connection, bytes_read)
self._response_already_sent = True

Expand Down