now with regex

This commit is contained in:
deronnax 2014-10-21 11:47:39 +02:00
parent b863e8390e
commit f846f107e6

View File

@ -36,6 +36,7 @@ import posixpath
import socket
import ssl
import wsgiref.simple_server
import re
# Manage Python2/3 different modules
# pylint: disable=F0401,E0611
try:
@ -55,6 +56,7 @@ VERSION = "0.9"
# Standard "not allowed" response that is returned when an authenticated user
# tries to access information they don't have rights to
NOT_ALLOWED = (client.FORBIDDEN, {}, None)
WELLKNOWNRE = re.compile(r'/.well-known/(carddav|caldav)/?')
class HTTPServer(wsgiref.simple_server.WSGIServer, object):
@ -286,10 +288,9 @@ class Application(object):
user = environ.get("REMOTE_USER")
password = None
if path.startswith('/.well-known/'):
fragment = path.rstrip("/").rsplit('/', 1)[-1]
redirect = config.get("well-known", fragment)
if redirect:
wkfragment = WELLKNOWNRE.match(path)
if wkfragment:
redirect = config.get("well-known", wkfragment.group(1))
if not user and "%(user)s" in redirect:
status = client.UNAUTHORIZED
headers = {