diff --git a/doc-src/features/upstreamproxy.html b/doc-src/features/upstreamproxy.html index 47bc115da..bb354cd3d 100644 --- a/doc-src/features/upstreamproxy.html +++ b/doc-src/features/upstreamproxy.html @@ -11,17 +11,3 @@ mitmproxy forwards ordinary HTTP requests to an upstream server. - -Here, **schema** is one of http, https, http2https or https2http. The latter -two extended schema specifications control the use of HTTP and HTTPS on -mitmproxy and the upstream server. You can indicate that mitmproxy should use -HTTP, and the upstream server uses HTTPS like this: - - http2https://hostname:port - -And you can indicate that mitmproxy should use HTTPS while the upstream -service uses HTTP like this: - - https2http://hostname:port - - diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index f5c66caab..185944da4 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -100,19 +100,13 @@ def parse_setheader(s): def parse_server_spec(url): - normalized_url = re.sub("^https?2", "", url) - - p = http.parse_url(normalized_url) - if not p or not p[1]: + p = http.parse_url(url) + if not p or not p[1] or p[0] not in ("http", "https"): raise configargparse.ArgumentTypeError( "Invalid server specification: %s" % url ) - if url.lower().startswith("https2http"): - ssl = [True, False] - elif url.lower().startswith("http2https"): - ssl = [False, True] - elif url.lower().startswith("https"): + if p[0].lower() == "https": ssl = [True, True] else: ssl = [False, False] @@ -120,6 +114,20 @@ def parse_server_spec(url): return ssl + list(p[1:3]) +def parse_server_spec_special(url): + """ + Provides additional support for http2https and https2http schemes. + """ + normalized_url = re.sub("^https?2", "", url) + ret = parse_server_spec(normalized_url) + if url.lower().startswith("https2http"): + ret[0] = True + elif url.lower().startswith("http2https"): + ret[0] = False + return ret + + + def get_common_options(options): stickycookie, stickyauth = None, None if options.stickycookie_filt: @@ -336,7 +344,7 @@ def common_options(parser): group.add_argument( "-R", "--reverse", action="store", - type=parse_server_spec, + type=parse_server_spec_special, dest="reverse_proxy", default=None, help="""