HTTPd, websrv_lib: implement extendable OPTIONS handler.
For CalDAV, we need to allow the handler to fine-tune its OPTIONS response. So, better cleanup the API and allow request handlers to define their OPTIONS. bzr revid: p_christ@hol.gr-20100726093336-afzp15rys9oua4a0
This commit is contained in:
parent
e8b1da52ab
commit
d131f6f42d
|
@ -297,7 +297,7 @@ def init_xmlrpc():
|
|||
|
||||
class StaticHTTPHandler(HttpLogHandler, FixSendError, HttpOptions, HTTPHandler):
|
||||
_logger = logging.getLogger('httpd')
|
||||
_HTTP_OPTIONS = 'OPTIONS GET HEAD'
|
||||
_HTTP_OPTIONS = { 'Allow': ['OPTIONS', 'GET', 'HEAD'] }
|
||||
|
||||
def __init__(self,request, client_address, server):
|
||||
HTTPHandler.__init__(self,request,client_address,server)
|
||||
|
|
|
@ -179,17 +179,37 @@ class FixSendError:
|
|||
self.wfile.write(content)
|
||||
|
||||
class HttpOptions:
|
||||
_HTTP_OPTIONS = 'OPTIONS'
|
||||
_HTTP_OPTIONS = {'Allow': ['OPTIONS' ] }
|
||||
|
||||
def do_OPTIONS(self):
|
||||
"""return the list of capabilities """
|
||||
|
||||
opts = self._HTTP_OPTIONS
|
||||
nopts = self._prep_OPTIONS(opts)
|
||||
if nopts:
|
||||
opts = nopts
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Length", 0)
|
||||
|
||||
self.send_header('Allow', self._HTTP_OPTIONS)
|
||||
for key, value in opts.items():
|
||||
if isinstance(value, basestring):
|
||||
self.send_header(key, value)
|
||||
elif isinstance(value, (tuple, list)):
|
||||
self.send_header(key, ', '.join(value))
|
||||
self.end_headers()
|
||||
|
||||
def _prep_OPTIONS(self, opts):
|
||||
"""Prepare the OPTIONS response, if needed
|
||||
|
||||
Sometimes, like in special DAV folders, the OPTIONS may contain
|
||||
extra keywords, perhaps also dependant on the request url.
|
||||
@param the options already. MUST be copied before being altered
|
||||
@return the updated options.
|
||||
|
||||
"""
|
||||
return opts
|
||||
|
||||
class MultiHTTPHandler(FixSendError, HttpOptions, BaseHTTPRequestHandler):
|
||||
""" this is a multiple handler, that will dispatch each request
|
||||
to a nested handler, iff it matches
|
||||
|
|
Loading…
Reference in New Issue