MCPcopy
hub / github.com/mitmproxy/mitmproxy / conn_text

Method conn_text

mitmproxy/tools/console/flowview.py:375–416  ·  view source on GitHub ↗
(self, conn)

Source from the content-addressed store, hash-verified

373 return f"{pretty.view_name} {pretty.description}", text_objects
374
375 def conn_text(self, conn):
376 if conn:
377 hdrs = []
378 for k, v in conn.headers.fields:
379 # This will always force an ascii representation of headers. For example, if the server sends a
380 #
381 # X-Authors: Made with ❤ in Hamburg
382 #
383 # header, mitmproxy will display the following:
384 #
385 # X-Authors: Made with \xe2\x9d\xa4 in Hamburg.
386 #
387 # The alternative would be to just use the header's UTF-8 representation and maybe
388 # do `str.replace("\t", "\\t")` to exempt tabs from urwid's special characters escaping [1].
389 # That would in some terminals allow rendering UTF-8 characters, but the mapping
390 # wouldn't be bijective, i.e. a user couldn't distinguish "\\t" and "\t".
391 # Also, from a security perspective, a mitmproxy user couldn't be fooled by homoglyphs.
392 #
393 # 1) https://github.com/mitmproxy/mitmproxy/issues/1833
394 # https://github.com/urwid/urwid/blob/6608ee2c9932d264abd1171468d833b7a4082e13/urwid/display_common.py#L35-L36,
395
396 k = strutils.bytes_to_escaped_str(k) + ":"
397 v = strutils.bytes_to_escaped_str(v)
398 hdrs.append((k, v))
399 txt = common.format_keyvals(hdrs, key_format="header")
400 viewmode = self.master.commands.call("console.flowview.mode")
401 msg, body = self.content_view(viewmode, conn)
402
403 txt.append(self._contentview_status_bar(msg, viewmode))
404 txt.extend(body)
405 else:
406 txt = [
407 urwid.Text(""),
408 urwid.Text(
409 [
410 ("highlight", "No response. Press "),
411 ("key", "e"),
412 ("highlight", " and edit any aspect to add one."),
413 ]
414 ),
415 ]
416 return searchable.Searchable(txt)
417
418 def dns_message_text(
419 self, type: str, message: DNSMessage | None

Callers 2

view_requestMethod · 0.95
view_responseMethod · 0.95

Calls 5

content_viewMethod · 0.95
appendMethod · 0.45
callMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected