diff --git a/pywb/utils.py b/pywb/utils.py index 2cc7ecac..e947f0a0 100644 --- a/pywb/utils.py +++ b/pywb/utils.py @@ -67,3 +67,11 @@ class PerfTimer: self.perfdict[self.name] = str(self.end - self.start) +# adapted from wsgiref.request_uri, but doesn't include domain name and allows ':' in url +def request_uri(environ, include_query=1): + """Return the requested path, optionally including the query string""" + from urllib import quote + url = quote(environ.get('SCRIPT_NAME', '')+environ.get('PATH_INFO',''),safe='/;=,:') + if include_query and environ.get('QUERY_STRING'): + url += '?' + environ['QUERY_STRING'] + return url \ No newline at end of file diff --git a/pywb/wbapp.py b/pywb/wbapp.py index 75b6bd7b..b81467f0 100644 --- a/pywb/wbapp.py +++ b/pywb/wbapp.py @@ -1,3 +1,4 @@ +from utils import request_uri from query import QueryHandler, EchoEnv, EchoRequest from replay import WBHandler import wbexceptions @@ -81,6 +82,7 @@ except: def application(env, start_response): + env['REQUEST_URI'] = request_uri(env) response = None try: diff --git a/pywb/wbexceptions.py b/pywb/wbexceptions.py index 22975422..e1c9a5bf 100644 --- a/pywb/wbexceptions.py +++ b/pywb/wbexceptions.py @@ -1,28 +1,28 @@ class RequestParseException(Exception): def status(_): - return '400' + return '400 Bad Request' class BadUrlException(Exception): def status(_): - return '400' + return '400 Bad Request' class AccessException(Exception): def status(_): - return '403' + return '403 Forbidden' class InvalidCDXException(Exception): def status(_): - return '500' + return '500 Internal Server Error' class NotFoundException(Exception): def status(_): - return '404' + return '404 Not Found' # Exceptions that effect a specific capture and result in a retry class CaptureException(Exception): def status(_): - return '500' + return '500 Internal Server Error' class UnresolvedArchiveFileException(CaptureException): pass @@ -45,7 +45,7 @@ class ArchiveLoadFailed(CaptureException): self.reason = reason def status(_): - return '503' + return '503 Service Unavailable' class InternalRedirect(Exception): def __init__(self, location, status = '302 Internal Redirect'): @@ -53,6 +53,6 @@ class InternalRedirect(Exception): self.status = status self.httpHeaders = [('Location', location)] - def status(_): + def status(self): return self.status