Grapnel: add stub GET handler

This commit is contained in:
James Lu 2022-07-25 23:55:19 -07:00
parent a017bd135f
commit 3e08495dab

View File

@ -43,9 +43,12 @@ _ = PluginInternationalization('Grapnel')
class GrappleHTTPCallback(httpserver.SupyHTTPServerCallback): class GrappleHTTPCallback(httpserver.SupyHTTPServerCallback):
name = 'Grapnel' 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_response(code)
handler.send_header('Content-type', 'text/plain') 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.end_headers()
handler.wfile.write(text.encode('utf-8')) handler.wfile.write(text.encode('utf-8'))
handler.wfile.write(b'\n') handler.wfile.write(b'\n')
@ -121,6 +124,10 @@ class GrappleHTTPCallback(httpserver.SupyHTTPServerCallback):
self._send_response(handler, 500, "Unspecified internal error") self._send_response(handler, 500, "Unspecified internal error")
raise 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' HTTP_ENDPOINT_NAME = 'grapnel'
# https://docs.python.org/3.10/library/secrets.html#how-many-bytes-should-tokens-use # https://docs.python.org/3.10/library/secrets.html#how-many-bytes-should-tokens-use