aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2020-02-28 19:48:48 +0100
committerMaximilian Hils <git@maximilianhils.com>2020-02-28 19:48:48 +0100
commit9387f0b28203779aa4d18368ebf0f92eee93b6e1 (patch)
tree5faa58a581f7d81a772316395a81b795b0076dc5 /mitmproxy
parentff759fa51b00c05c3873efaa8ae16abe3d078bfb (diff)
downloadmitmproxy-9387f0b28203779aa4d18368ebf0f92eee93b6e1.tar.gz
mitmproxy-9387f0b28203779aa4d18368ebf0f92eee93b6e1.tar.bz2
mitmproxy-9387f0b28203779aa4d18368ebf0f92eee93b6e1.zip
minor code style improvements, sync sans-io changes
Diffstat (limited to 'mitmproxy')
-rw-r--r--mitmproxy/net/server_spec.py8
-rw-r--r--mitmproxy/proxy/protocol/http.py6
2 files changed, 10 insertions, 4 deletions
diff --git a/mitmproxy/net/server_spec.py b/mitmproxy/net/server_spec.py
index efbf1012..c877e6e1 100644
--- a/mitmproxy/net/server_spec.py
+++ b/mitmproxy/net/server_spec.py
@@ -1,13 +1,17 @@
"""
Parse scheme, host and port from a string.
"""
-import collections
import re
+import typing
from typing import Tuple
from mitmproxy.net import check
-ServerSpec = collections.namedtuple("ServerSpec", ["scheme", "address"])
+
+class ServerSpec(typing.NamedTuple):
+ scheme: str
+ address: typing.Tuple[str, int]
+
server_spec_re = re.compile(
r"""
diff --git a/mitmproxy/proxy/protocol/http.py b/mitmproxy/proxy/protocol/http.py
index 4c20617b..37e1669e 100644
--- a/mitmproxy/proxy/protocol/http.py
+++ b/mitmproxy/proxy/protocol/http.py
@@ -1,3 +1,5 @@
+import textwrap
+
import h2.exceptions
import time
import enum
@@ -142,13 +144,13 @@ def validate_request_form(mode, request):
allowed_request_forms = MODE_REQUEST_FORMS[mode]
if request.first_line_format not in allowed_request_forms:
if mode == HTTPMode.transparent:
- err_message = (
+ err_message = textwrap.dedent((
"""
Mitmproxy received an {} request even though it is not running
in regular mode. This usually indicates a misconfiguration,
please see the mitmproxy mode documentation for details.
"""
- ).format("HTTP CONNECT" if request.first_line_format == "authority" else "absolute-form")
+ )).strip().format("HTTP CONNECT" if request.first_line_format == "authority" else "absolute-form")
else:
err_message = "Invalid HTTP request form (expected: %s, got: %s)" % (
" or ".join(allowed_request_forms), request.first_line_format