mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-19 08:59:27 +01:00
httpserver: Respond to HEAD requests. Closes GH-1203.
This commit is contained in:
parent
1d162dd048
commit
4576874128
@ -119,7 +119,7 @@ httpserver.set_default_templates(DEFAULT_TEMPLATES)
|
||||
class FactoidsCallback(httpserver.SupyHTTPServerCallback):
|
||||
name = 'Factoids web interface'
|
||||
|
||||
def doGet(self, handler, path):
|
||||
def doGetOrHead(self, handler, path, write_content):
|
||||
parts = path.split('/')[1:]
|
||||
if path == '/':
|
||||
self.send_response(200)
|
||||
@ -132,6 +132,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback):
|
||||
self.send_response(404)
|
||||
self.send_header('Content-type', 'text/html; charset=utf-8')
|
||||
self.end_headers()
|
||||
if write_content:
|
||||
self.write(httpserver.get_template('generic/error.html')%
|
||||
{'title': 'Factoids - not a channel',
|
||||
'error': 'This is not a channel'})
|
||||
@ -140,6 +141,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback):
|
||||
self.send_response(403)
|
||||
self.send_header('Content-type', 'text/html; charset=utf-8')
|
||||
self.end_headers()
|
||||
if write_content:
|
||||
self.write(httpserver.get_template('generic/error.html')%
|
||||
{'title': 'Factoids - unavailable',
|
||||
'error': 'This channel does not exist or its factoids '
|
||||
@ -173,6 +175,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/html; charset=utf-8')
|
||||
self.end_headers()
|
||||
if write_content:
|
||||
self.write(httpserver.get_template('factoids/channel.html')%
|
||||
{'channel': channel, 'rows': content})
|
||||
def doPost(self, handler, path, form):
|
||||
|
@ -305,15 +305,21 @@ class SupyHTTPServerCallback(log.Firewalled):
|
||||
def write(self, s):
|
||||
self.wfile.write(s)
|
||||
|
||||
def doGet(self, handler, path, *args, **kwargs):
|
||||
def doGetOrHead(self, handler, path, write_content):
|
||||
response = self.defaultResponse.encode()
|
||||
handler.send_response(405)
|
||||
self.send_header('Content-Type', 'text/plain; charset=utf-8; charset=utf-8')
|
||||
self.send_header('Content-Length', len(response))
|
||||
self.end_headers()
|
||||
if write_content:
|
||||
self.wfile.write(response)
|
||||
|
||||
doPost = doHead = doGet
|
||||
def doGet(self, handler, path):
|
||||
self.doGetOrHead(handler, path, write_content=True)
|
||||
def doHead(self, handler, path):
|
||||
self.doGetOrHead(handler, path, write_content=False)
|
||||
|
||||
doPost = doGet
|
||||
|
||||
def doHook(self, handler, subdir):
|
||||
"""Method called when hooking this callback."""
|
||||
@ -331,7 +337,7 @@ class Supy404(SupyHTTPServerCallback):
|
||||
if I don't know what to serve.
|
||||
What I'm saying is you just triggered a 404 Not Found, and I am not
|
||||
trained to help you in such a case.""")
|
||||
def doGet(self, handler, path, *args, **kwargs):
|
||||
def doGetOrHead(self, handler, path, write_content):
|
||||
response = self.response
|
||||
if minisix.PY3:
|
||||
response = response.encode()
|
||||
@ -339,16 +345,15 @@ class Supy404(SupyHTTPServerCallback):
|
||||
self.send_header('Content-Type', 'text/plain; charset=utf-8; charset=utf-8')
|
||||
self.send_header('Content-Length', len(self.response))
|
||||
self.end_headers()
|
||||
if write_content:
|
||||
self.wfile.write(response)
|
||||
|
||||
doPost = doHead = doGet
|
||||
|
||||
class SupyIndex(SupyHTTPServerCallback):
|
||||
"""Displays the index of available plugins."""
|
||||
name = "index"
|
||||
fullpath = True
|
||||
defaultResponse = _("Request not handled.")
|
||||
def doGet(self, handler, path):
|
||||
def doGetOrHead(self, handler, path, write_content):
|
||||
plugins = [x for x in handler.server.callbacks.items()]
|
||||
if plugins == []:
|
||||
plugins = _('No plugins available.')
|
||||
@ -362,6 +367,7 @@ class SupyIndex(SupyHTTPServerCallback):
|
||||
self.send_header('Content-Type', 'text/html; charset=utf-8')
|
||||
self.send_header('Content-Length', len(response))
|
||||
self.end_headers()
|
||||
if write_content:
|
||||
self.wfile.write(response)
|
||||
|
||||
class Static(SupyHTTPServerCallback):
|
||||
@ -372,7 +378,7 @@ class Static(SupyHTTPServerCallback):
|
||||
def __init__(self, mimetype='text/plain; charset=utf-8'):
|
||||
super(Static, self).__init__()
|
||||
self._mimetype = mimetype
|
||||
def doGet(self, handler, path):
|
||||
def doGetOrHead(self, handler, path, write_content):
|
||||
response = get_template(path)
|
||||
if minisix.PY3:
|
||||
response = response.encode()
|
||||
@ -380,13 +386,14 @@ class Static(SupyHTTPServerCallback):
|
||||
self.send_header('Content-type', self._mimetype)
|
||||
self.send_header('Content-Length', len(response))
|
||||
self.end_headers()
|
||||
if write_content:
|
||||
self.wfile.write(response)
|
||||
|
||||
class Favicon(SupyHTTPServerCallback):
|
||||
"""Services the favicon.ico file to browsers."""
|
||||
name = 'favicon'
|
||||
defaultResponse = _('Request not handled')
|
||||
def doGet(self, handler, path):
|
||||
def doGetOrHead(self, handler, path, write_content):
|
||||
response = None
|
||||
file_path = conf.supybot.servers.http.favicon()
|
||||
if file_path:
|
||||
@ -407,6 +414,7 @@ class Favicon(SupyHTTPServerCallback):
|
||||
# self.send_header('Content-Length', len(response))
|
||||
# self.send_header('Content-type', 'image/' + ext)
|
||||
# self.end_headers()
|
||||
if write_content:
|
||||
self.wfile.write(response)
|
||||
else:
|
||||
response = _('No favicon set.')
|
||||
@ -416,6 +424,7 @@ class Favicon(SupyHTTPServerCallback):
|
||||
self.send_header('Content-type', 'text/plain; charset=utf-8')
|
||||
self.send_header('Content-Length', len(response))
|
||||
self.end_headers()
|
||||
if write_content:
|
||||
self.wfile.write(response)
|
||||
|
||||
http_servers = []
|
||||
|
Loading…
Reference in New Issue
Block a user