mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-04-22 19:47:56 +08:00
Internal error page for WSGI.
Also, 100% test coverage.
This commit is contained in:
@@ -55,6 +55,23 @@ class WSGIAdaptor:
|
||||
environ[key] = value
|
||||
return environ
|
||||
|
||||
def error_page(self, soc, headers_sent):
|
||||
"""
|
||||
Make a best-effort attempt to write an error page. If headers are
|
||||
already sent, we just bung the error into the page.
|
||||
"""
|
||||
c = """
|
||||
<html>
|
||||
<h1>Internal Server Error</h1>
|
||||
</html>
|
||||
"""
|
||||
if not headers_sent:
|
||||
soc.write("HTTP/1.1 500 Internal Server Error%s\r\n")
|
||||
soc.write("Content-Type: text/html\r\n")
|
||||
soc.write("Content-Length: %s\r\n"%len(c))
|
||||
soc.write("\r\n")
|
||||
soc.write(c)
|
||||
|
||||
def serve(self, request, soc):
|
||||
state = dict(
|
||||
response_started = False,
|
||||
@@ -97,12 +114,12 @@ class WSGIAdaptor:
|
||||
if not state["headers_sent"]:
|
||||
write("")
|
||||
except Exception, v:
|
||||
print v
|
||||
try:
|
||||
# Serve internal server error page
|
||||
pass
|
||||
self.error_page(soc, state["headers_sent"])
|
||||
# begin nocover
|
||||
except Exception, v:
|
||||
pass
|
||||
# end nocover
|
||||
return errs.getvalue()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user