2 Commits

Author SHA1 Message Date
klemek 1e5f3ba986 chore: release 1.4.0
Python Lint CI / ruff (push) Successful in 2m16s
Docker CI / docker-build (push) Successful in 3m8s
Python Lint CI / ruff-format-check (push) Successful in 2m33s
Python Lint CI / ty (push) Successful in 5m13s
Python Test CI / coverage (push) Successful in 5m6s
2026-05-11 17:26:42 +02:00
klemek d3d98bd9b2 feat: handle HEAD requests 2026-05-11 17:26:21 +02:00
4 changed files with 26 additions and 8 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "stapler"
version = "1.3.2"
version = "1.4.0"
description = "Static pages as simple as a gzip file"
requires-python = ">=3.14"
dependencies = [
+9 -4
View File
@@ -153,7 +153,8 @@ class BaseHandler(abc.ABC, http.server.BaseHTTPRequestHandler):
self.send_header("Content-Length", str(len(encoded)))
self.send_header("Connection", "close")
self.end_headers()
self.wfile.write(encoded)
if self.command != http.HTTPMethod.HEAD:
self.wfile.write(encoded)
self.close_connection = True
def send_status_only(
@@ -222,7 +223,7 @@ class BaseHandler(abc.ABC, http.server.BaseHTTPRequestHandler):
self.send_header("Content-Length", str(out_size := len(response.content)))
self.send_header("Connection", "close")
self.end_headers()
if out_size > 0:
if out_size > 0 and self.command != http.HTTPMethod.HEAD:
self.wfile.write(response.content)
self.close_connection = True
@@ -387,9 +388,13 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler, BaseHandler):
def do_HEAD(self) -> None:
with self.handle_errors():
self._pre_log_request()
if not self._proxy_or_redirect():
super().do_HEAD()
if self._proxy_or_redirect():
return None
if self.path == "/" and self.host == self.default_host:
return self.send_basic_body(self.server_signature())
super().do_HEAD()
self.close_connection = True
return None
@typing.override
def do_GET(self) -> None:
+15 -2
View File
@@ -36,6 +36,7 @@ class BaseHandlerTestCase(BaseTestCase, abc.ABC):
code: int,
message: str | None = None,
headers: dict[str, str] | None = None,
content_length: int = 0,
) -> typing.Iterator[None]:
if headers is None:
headers = {}
@@ -46,7 +47,7 @@ class BaseHandlerTestCase(BaseTestCase, abc.ABC):
send_response_mock.assert_called_once_with(code, message)
send_header_mock.assert_has_calls(
[
unittest.mock.call("Content-Length", "0"),
unittest.mock.call("Content-Length", str(content_length)),
]
+ [unittest.mock.call(header, value) for header, value in headers.items()],
any_order=True,
@@ -192,9 +193,21 @@ class TestRequestHandler(BaseHandlerTestCase):
token_manager=self.token_manager,
)
def test_do_head_forward(self) -> None:
def test_do_head_index(self) -> None:
handler = self._get_handler()
with (
self.expects_status_only(
handler, 200, content_length=len(handler.server_signature())
),
self.patch("http.server.SimpleHTTPRequestHandler.do_HEAD", count=0),
self.seal_mocks(),
):
handler.do_HEAD()
def test_do_head_forward(self) -> None:
handler = self._get_handler("/file")
with (
self.mock_call(self.registry.get_from_path, ["file"], Page("file")),
self.patch("http.server.SimpleHTTPRequestHandler.do_HEAD"),
self.seal_mocks(),
):
Generated
+1 -1
View File
@@ -212,7 +212,7 @@ wheels = [
[[package]]
name = "stapler"
version = "1.3.2"
version = "1.4.0"
source = { editable = "." }
dependencies = [
{ name = "requests" },