refactor(handlers): handle all http methods

This commit is contained in:
2026-04-20 13:51:19 +02:00
parent 4e50c42100
commit fb70638330
2 changed files with 38 additions and 0 deletions
+18
View File
@@ -313,12 +313,30 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler, BaseHandler):
self.registry.set_host(path, self.target_host)
return None
def do_POST(self) -> None:
self.do_PUT() # be gentle on them
def do_PATCH(self) -> None:
self.do_PUT() # be gentle on them
def do_DELETE(self) -> None:
self._pre_log_request()
if (path := self.__check_update_request()) is None:
return None
return self._update_remove(path)
def do_CONNECT(self) -> None:
self._pre_log_request()
self.send_error(http.HTTPStatus.METHOD_NOT_ALLOWED)
def do_OPTIONS(self) -> None:
self._pre_log_request()
self.send_error(http.HTTPStatus.METHOD_NOT_ALLOWED)
def do_TRACE(self) -> None:
self._pre_log_request()
self.send_error(http.HTTPStatus.METHOD_NOT_ALLOWED)
def _update_extract(self, path: str) -> None:
if self.in_size == 0:
return self.send_error(http.HTTPStatus.LENGTH_REQUIRED, "No body found")
+20
View File
@@ -243,6 +243,26 @@ class TestRequestHandler(BaseHandlerTestCase):
):
handler.do_PUT()
def test_do_post_is_do_put(self) -> None:
handler = self._get_handler("/path")
with (
self.expects_error(
handler, http.HTTPStatus.BAD_REQUEST, "No X-Token header in request"
),
self.seal_mocks(),
):
handler.do_POST()
def test_do_patch_is_do_put(self) -> None:
handler = self._get_handler("/path")
with (
self.expects_error(
handler, http.HTTPStatus.BAD_REQUEST, "No X-Token header in request"
),
self.seal_mocks(),
):
handler.do_PATCH()
def test_do_put_invalid_token(self) -> None:
handler = self._get_handler("/path", {"X-Token": "secret"})
with (