aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2020-02-28 20:00:15 +0100
committerGitHub <noreply@github.com>2020-02-28 20:00:15 +0100
commit6d3b8c9716a274fdcc72c4dc9a841f2e8fa4d1e9 (patch)
treec5c192c9e03401d5fe499ed50cc96348e1790567 /mitmproxy
parentc284d595a34a16d76e18fa4e8654b4c14ea327fd (diff)
parent9387f0b28203779aa4d18368ebf0f92eee93b6e1 (diff)
downloadmitmproxy-6d3b8c9716a274fdcc72c4dc9a841f2e8fa4d1e9.tar.gz
mitmproxy-6d3b8c9716a274fdcc72c4dc9a841f2e8fa4d1e9.tar.bz2
mitmproxy-6d3b8c9716a274fdcc72c4dc9a841f2e8fa4d1e9.zip
Merge pull request #3841 from mhils/sans-io-adjustments
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