Merge pull request #3841 from mhils/sans-io-adjustments

Minor code style improvements, sync sans-io changes
This commit is contained in:
Maximilian Hils 2020-02-28 20:00:15 +01:00 committed by GitHub
commit 6d3b8c9716
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -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"""

View File

@ -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