Skip to content

Commit

Permalink
Refactored use of server-replay-nopop to server-reply-pop (#6123)
Browse files Browse the repository at this point in the history
* server-replay-nopop -> server-replay-pop

Co-authored-by: Pradyot Ranjan <99216956+prady0t@users.noreply.github.com>

* server-replay-pop -> server-replay-reuse

---------

Co-authored-by: Maximilian Hils <git@maximilianhils.com>
  • Loading branch information
prady0t and mhils committed Jul 2, 2023
1 parent fd01a0a commit cb131b6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
([#6088](https://github.com/mitmproxy/mitmproxy/pull/6088), @sujaldev)
* Fix a bug where a server connection timeout would cause requests to be issued with a wrong SNI in reverse proxy mode.
([#6148](https://github.com/mitmproxy/mitmproxy/pull/6148), @mhils)
* The `server_replay_nopop` option has been renamed to `server_replay_reuse` to avoid confusing double-negation.
([#6084](https://github.com/mitmproxy/mitmproxy/issues/6084), @prady0t, @Semnodime)
* Add zstd to valid gRPC encoding schemes.
([#6188](https://github.com/mitmproxy/mitmproxy/pull/6188), @tsaaristo)
* For reverse proxy directly accessed via IP address, the IP address is now included
Expand Down
18 changes: 16 additions & 2 deletions mitmproxy/addons/serverplayback.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from mitmproxy import http
from mitmproxy import io

logger = logging.getLogger(__name__)


class ServerPlayback:
flowmap: dict[Hashable, list[http.HTTPFlow]]
Expand All @@ -31,14 +33,22 @@ def load(self, loader):
"Kill extra requests during replay (for which no replayable response was found).",
)
loader.add_option(
"server_replay_nopop",
"server_replay_reuse",
bool,
False,
"""
Don't remove flows from server replay state after use. This makes it
possible to replay same response multiple times.
""",
)
loader.add_option(
"server_replay_nopop",
bool,
False,
"""
Deprecated alias for `server_replay_reuse`.
""",
)
loader.add_option(
"server_replay_refresh",
bool,
Expand Down Expand Up @@ -201,7 +211,7 @@ def next_flow(self, flow: http.HTTPFlow) -> http.HTTPFlow | None:
"""
hash = self._hash(flow)
if hash in self.flowmap:
if ctx.options.server_replay_nopop:
if ctx.options.server_replay_reuse or ctx.options.server_replay_nopop:
return next(
(flow for flow in self.flowmap[hash] if flow.response), None
)
Expand All @@ -220,6 +230,10 @@ def next_flow(self, flow: http.HTTPFlow) -> http.HTTPFlow | None:
return None

def configure(self, updated):
if ctx.options.server_replay_nopop: # pragma: no cover
logger.error(
"server_replay_nopop has been renamed to server_replay_reuse, please update your config."
)
if not self.configured and ctx.options.server_replay:
self.configured = True
try:
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy/tools/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def common_options(parser, opts):
group = parser.add_argument_group("Server Replay")
opts.make_parser(group, "server_replay", metavar="PATH", short="S")
opts.make_parser(group, "server_replay_kill_extra")
opts.make_parser(group, "server_replay_nopop")
opts.make_parser(group, "server_replay_reuse")
opts.make_parser(group, "server_replay_refresh")

# Map Remote
Expand Down
4 changes: 3 additions & 1 deletion mitmproxy/utils/arg_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
-f
--filter
--socks
--server-replay-nopop
"""

REPLACEMENTS = {
Expand All @@ -75,7 +76,7 @@
"--upstream-trusted-confdir": "ssl_verify_upstream_trusted_confdir",
"--upstream-trusted-ca": "ssl_verify_upstream_trusted_ca",
"--no-onboarding": "onboarding",
"--no-pop": "server_replay_nopop",
"--no-pop": "server_replay_reuse",
"--replay-ignore-content": "server_replay_ignore_content",
"--replay-ignore-payload-param": "server_replay_ignore_payload_params",
"--replay-ignore-param": "server_replay_ignore_params",
Expand All @@ -102,6 +103,7 @@
"-f": "--view-filter",
"--filter": "--view-filter",
"--socks": "--mode socks5",
"--server-replay-nopop": "--server-replay-reuse",
}


Expand Down
4 changes: 2 additions & 2 deletions test/mitmproxy/addons/test_serverplayback.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ def test_load():
assert not s.next_flow(r)


def test_load_with_server_replay_nopop():
def test_load_with_server_replay_reuse():
s = serverplayback.ServerPlayback()
with taddons.context(s) as tctx:
tctx.configure(s, server_replay_nopop=True)
tctx.configure(s, server_replay_reuse=True)

r = tflow.tflow(resp=True)
r.request.headers["key"] = "one"
Expand Down

0 comments on commit cb131b6

Please sign in to comment.