refactor(handlers): handle all http methods
This commit is contained in:
@@ -313,12 +313,30 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler, BaseHandler):
|
|||||||
self.registry.set_host(path, self.target_host)
|
self.registry.set_host(path, self.target_host)
|
||||||
return None
|
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:
|
def do_DELETE(self) -> None:
|
||||||
self._pre_log_request()
|
self._pre_log_request()
|
||||||
if (path := self.__check_update_request()) is None:
|
if (path := self.__check_update_request()) is None:
|
||||||
return None
|
return None
|
||||||
return self._update_remove(path)
|
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:
|
def _update_extract(self, path: str) -> None:
|
||||||
if self.in_size == 0:
|
if self.in_size == 0:
|
||||||
return self.send_error(http.HTTPStatus.LENGTH_REQUIRED, "No body found")
|
return self.send_error(http.HTTPStatus.LENGTH_REQUIRED, "No body found")
|
||||||
|
|||||||
@@ -243,6 +243,26 @@ class TestRequestHandler(BaseHandlerTestCase):
|
|||||||
):
|
):
|
||||||
handler.do_PUT()
|
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:
|
def test_do_put_invalid_token(self) -> None:
|
||||||
handler = self._get_handler("/path", {"X-Token": "secret"})
|
handler = self._get_handler("/path", {"X-Token": "secret"})
|
||||||
with (
|
with (
|
||||||
|
|||||||
Reference in New Issue
Block a user