mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
wsgiref compatibility fixes.
- Manually set env[‘REQUEST_URI’] (which is nonstandard) the same way it’s set by uwsgi. - Include HTTP error code reasons in error response. (wsgiref checks that error code is at least 4 characters, i.e. includes reason)
This commit is contained in:
parent
6cb1743163
commit
595c9b0c3c
@ -107,6 +107,14 @@ def iso_date_to_timestamp(string):
|
||||
return datetime_to_timestamp(iso_date_to_datetime(string))
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user