From 3e08495dab55b2fc228853c51eb413d9a516b4ad Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 25 Jul 2022 23:55:19 -0700 Subject: [PATCH] Grapnel: add stub GET handler --- Grapnel/plugin.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Grapnel/plugin.py b/Grapnel/plugin.py index 6f9bf74..c82e94d 100644 --- a/Grapnel/plugin.py +++ b/Grapnel/plugin.py @@ -43,9 +43,12 @@ _ = PluginInternationalization('Grapnel') class GrappleHTTPCallback(httpserver.SupyHTTPServerCallback): name = 'Grapnel' - def _send_response(self, handler, code, text): + def _send_response(self, handler, code, text, extra_headers=None): handler.send_response(code) handler.send_header('Content-type', 'text/plain') + if extra_headers: + for header_pair in extra_headers: + handler.send_header(*header_pair) handler.end_headers() handler.wfile.write(text.encode('utf-8')) handler.wfile.write(b'\n') @@ -121,6 +124,10 @@ class GrappleHTTPCallback(httpserver.SupyHTTPServerCallback): self._send_response(handler, 500, "Unspecified internal error") raise + def doGet(self, handler, path): + self._send_response(handler, 405, "Only POST requests are supported by this service", + extra_headers=[('Allow', 'POST')]) + HTTP_ENDPOINT_NAME = 'grapnel' # https://docs.python.org/3.10/library/secrets.html#how-many-bytes-should-tokens-use