diff --git a/docs/src/content/overview-features.md b/docs/src/content/overview-features.md index 68271919e..a49716ed1 100644 --- a/docs/src/content/overview-features.md +++ b/docs/src/content/overview-features.md @@ -49,13 +49,15 @@ The `map_remote` option lets you specify an arbitrary number of patterns that define replacements within HTTP request URLs before they are sent to a server. The substituted URL is fetched instead of the original resource and the corresponding HTTP response is returned transparently to the client. +Note that if the original destination uses HTTP2, the substituted destination +needs to support HTTP2 as well, otherwise the substituted request may fail. `map_remote` patterns looks like this: ``` -:flow-filter:regex:replacement -:flow-filter:regex:@file-path -:regex:replacement -:regex:@file-path +|flow-filter|regex|replacement +|flow-filter|regex|@file-path +|regex|replacement +|regex|@file-path ``` * **flow-filter** is an optional mitmproxy [filter expression]({{< relref "concepts-filters">}}) @@ -70,10 +72,12 @@ The _separator_ is arbitrary, and is defined by the first character. ### Examples -Map all requests ending with `.jpg` to `https://placedog.net/640/480?random`: +Map all requests ending with `.jpg` to `https://placedog.net/640/480?random`. +Note that this might fail if the original HTTP request destination uses HTTP2 but the replaced +destination does not support HTTP2. ``` -:.*\.jpg$:https://placedog.net/640/480?random +|.*\.jpg$|https://placedog.net/640/480?random ``` Re-route all GET requests from `example.org` to `mitmproxy.org` (using `|` as the separator): diff --git a/mitmproxy/addons/mapremote.py b/mitmproxy/addons/mapremote.py index 5b6f2b202..1c1a7b900 100644 --- a/mitmproxy/addons/mapremote.py +++ b/mitmproxy/addons/mapremote.py @@ -4,7 +4,6 @@ import typing from mitmproxy import exceptions from mitmproxy import ctx -from mitmproxy.utils import strutils from mitmproxy.addons.modifyheaders import parse_modify_spec, ModifySpec @@ -62,5 +61,5 @@ class MapRemote: return replacements = 0 - obj.url, replacements = re.subn(search, repl, strutils.escaped_str_to_bytes(obj.pretty_url), flags=re.DOTALL) + obj.url, replacements = re.subn(search, repl, obj.pretty_url.encode("utf8", "surrogateescape"), flags=re.DOTALL) return replacements