MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / _search

Method _search

examples/contrib/search.py:18–65  ·  view source on GitHub ↗

Defines a command named "search" that matches the given regular expression against most parts of each request/response included in the selected flows. Usage: from the flow list view, type ":search" followed by a space, then a flow selection expression; e.g.,

(self, flows: Sequence[flow.Flow], regex: str)

Source from the content-addressed store, hash-verified

16
17 @command.command("search")
18 def _search(self, flows: Sequence[flow.Flow], regex: str) -> None:
19 """
20 Defines a command named "search" that matches
21 the given regular expression against most parts
22 of each request/response included in the selected flows.
23
24 Usage: from the flow list view, type ":search" followed by
25 a space, then a flow selection expression; e.g., "@shown",
26 then the desired regular expression to perform the search.
27
28 Alternatively, define a custom shortcut in keys.yaml; e.g.:
29 -
30 key: "/"
31 ctx: ["flowlist"]
32 cmd: "console.command search @shown "
33
34 Flows containing matches to the expression will be marked
35 with the magnifying glass emoji, and their comments will
36 contain JSON-formatted search results.
37
38 To view flow comments, enter the flow view
39 and navigate to the detail tab.
40 """
41
42 try:
43 self.exp = re.compile(regex)
44 except re.error as e:
45 logging.error(e)
46 return
47
48 for _flow in flows:
49 # Erase previous results while preserving other comments:
50 comments = list()
51 for c in _flow.comment.split("\n"):
52 if c.startswith(RESULTS_STR):
53 break
54 comments.append(c)
55 _flow.comment = "\n".join(comments)
56
57 if _flow.marked == MARKER:
58 _flow.marked = False
59
60 results = {k: v for k, v in self.flow_results(_flow).items() if v}
61 if results:
62 comments.append(RESULTS_STR)
63 comments.append(dumps(results, indent=2))
64 _flow.comment = "\n".join(comments)
65 _flow.marked = MARKER
66
67 def header_results(self, message):
68 results = {k: self.exp.findall(v) for k, v in message.headers.items()}

Callers

nothing calls this directly

Calls 7

flow_resultsMethod · 0.95
dumpsFunction · 0.85
errorMethod · 0.45
splitMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected