mirror of
https://github.com/mitmproxy/mitmproxy.git
synced 2024-11-23 21:30:04 +00:00
improve logging
This commit is contained in:
parent
2b2d21aff0
commit
5a2a5760d0
@ -990,24 +990,36 @@ class HTTPHandler(ProtocolHandler):
|
|||||||
def handle_error(self, error, flow=None):
|
def handle_error(self, error, flow=None):
|
||||||
|
|
||||||
message = repr(error)
|
message = repr(error)
|
||||||
if "tlsv1 alert unknown ca" in message:
|
message_debug = None
|
||||||
message += " The client does not trust the proxy's certificate."
|
|
||||||
|
|
||||||
if isinstance(error, tcp.NetLibDisconnect):
|
if isinstance(error, tcp.NetLibDisconnect):
|
||||||
self.c.log("TCP connection closed unexpectedly.", "debug")
|
message = None
|
||||||
else:
|
message_debug = "TCP connection closed unexpectedly."
|
||||||
self.c.log("error: %s" % message, level="info")
|
elif "tlsv1 alert unknown ca" in message:
|
||||||
|
message = "TLSv1 Alert Unknown CA: The client does not trust the proxy's certificate."
|
||||||
|
elif "handshake error" in message:
|
||||||
|
message_debug = message
|
||||||
|
message = "SSL handshake error: The client may not trust the proxy's certificate."
|
||||||
|
|
||||||
|
if message:
|
||||||
|
self.c.log(message, level="info")
|
||||||
|
if message_debug:
|
||||||
|
self.c.log(message, level="debug")
|
||||||
|
|
||||||
if flow:
|
if flow:
|
||||||
# TODO: no flows without request or with both request and response at the moment.
|
# TODO: no flows without request or with both request and response at the moment.
|
||||||
if flow.request and not flow.response:
|
if flow.request and not flow.response:
|
||||||
flow.error = Error(message)
|
flow.error = Error(message or message_debug)
|
||||||
self.c.channel.ask("error", flow)
|
self.c.channel.ask("error", flow)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
code = getattr(error, "code", 502)
|
code = getattr(error, "code", 502)
|
||||||
headers = getattr(error, "headers", None)
|
headers = getattr(error, "headers", None)
|
||||||
self.send_error(code, message, headers)
|
|
||||||
|
html_message = message or ""
|
||||||
|
if message_debug:
|
||||||
|
html_message += "<pre>%s</pre>" % message_debug
|
||||||
|
self.send_error(code, html_message, headers)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user