Unify Replacement UX
See original GitHub issueProblem Description
The replacement addon currently calls flow.replace()
, which performs replacements in URL, HTTP Headers, and request/response body. This is messy and terrible because there is no way to control in which part of the flow replacements should be done - it does many things, and none of them well. It’s often luck that replacements work. For example, in many cases, replacements like /~s/response-body
“work” because URL/header replacements are not performed if they don’t match syntactically:
I think there is some opportunity for improvement here. 😄
Proposed Changes
With the advent of a “map local” editor in #3940, I think it is time to clean up things here and implement the following changes:
- The replacements addon is for HTTP body replacements (and later on TCP/WebSocket messages). We can possibly rename it to make this more clear (ReplaceContent? ReplaceData?). This also means we can implement it in the addon and get rid of
HTTPFlow.replace
and its descendants. SetHeaders
is for header modifications.- Map remote/map local addons are for request line modification/redirection to localhost.
This also means we can unify the expression syntax for these four addons:
old syntax | new syntax | |
---|---|---|
Map Local | [/filter]/url/file-or-directory |
|
Map Remote | [/filter]/url-regex/replacement |
|
SetHeader | /filter/name/value |
[/filter]/header-name/[@]header-value |
Replacements | /filter[/regex]/[@]replacement |
[/filter]/body-regex/[@]replacement |
@mitmproxy/devs, @Prinzhorn, @naivekun, any thoughts? 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (17 by maintainers)
Top GitHub Comments
Yes, complete. 😃 👍
Just don’t escape them, it will match the right things anyways 😉🙊
More seriously: I see your point, but globs are very much limited when it comes to replacements and not just matching. Let’s keep this in mind, but we likely need regexes somewhere anyways, and then it may pay off to be consistent.