httpserver: Fix Content-type of default.css which caused the stylesheet not to be applied.

This commit is contained in:
Valentin Lorentz 2013-06-01 10:11:44 +02:00
parent 792df99688
commit 1a71fa2d81

View File

@ -56,10 +56,10 @@ class RequestNotHandled(Exception):
DEFAULT_TEMPLATES = { DEFAULT_TEMPLATES = {
'index.html': """\ 'index.html': """\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<title>""" + _('Supybot Web server index') + """</title> <title>""" + _('Supybot Web server index') + """</title>
<link rel="stylesheet" href="/default.css" /> <link rel="stylesheet" type="text/css" href="/default.css" media="screen" />
</head> </head>
<body class="purelisting"> <body class="purelisting">
<h1>Supybot web server index</h1> <h1>Supybot web server index</h1>
@ -206,8 +206,10 @@ class SupyHTTPRequestHandler(BaseHTTPRequestHandler):
def do_X(self, callbackMethod, *args, **kwargs): def do_X(self, callbackMethod, *args, **kwargs):
if self.path == '/': if self.path == '/':
callback = SupyIndex() callback = SupyIndex()
elif self.path in ('/robots.txt', '/default.css'): elif self.path in ('/robots.txt',):
callback = Static() callback = Static('text/plain')
elif self.path in ('/default.css',):
callback = Static('text/css')
elif self.path == '/favicon.ico': elif self.path == '/favicon.ico':
callback = Favicon() callback = Favicon()
else: else:
@ -250,7 +252,7 @@ class SupyHTTPRequestHandler(BaseHTTPRequestHandler):
log.info('HTTP request: %s - %s' % log.info('HTTP request: %s - %s' %
(self.address_string(), format % args)) (self.address_string(), format % args))
class SupyHTTPServerCallback: class SupyHTTPServerCallback(object):
"""This is a base class that should be overriden by any plugin that want """This is a base class that should be overriden by any plugin that want
to have a Web interface.""" to have a Web interface."""
fullpath = False fullpath = False
@ -318,10 +320,13 @@ class Static(SupyHTTPServerCallback):
fullpath = True fullpath = True
name = 'static' name = 'static'
defaultResponse = _('Request not handled') defaultResponse = _('Request not handled')
def __init__(self, mimetype='text/plain'):
super(Static, self).__init__()
self._mimetype = mimetype
def doGet(self, handler, path): def doGet(self, handler, path):
response = get_template(path) response = get_template(path)
handler.send_response(200) handler.send_response(200)
self.send_header('Content-type', 'text/plain') self.send_header('Content-type', self._mimetype)
self.send_header('Content-Length', len(response)) self.send_header('Content-Length', len(response))
self.end_headers() self.end_headers()
self.wfile.write(response) self.wfile.write(response)