MCPcopy
hub / github.com/mitmproxy/mitmproxy / get_text

Method get_text

mitmproxy/http.py:427–441  ·  view source on GitHub ↗

Similar to `Message.text`, but does not raise if `strict` is `False`. Instead, the message body is returned as surrogate-escaped UTF-8.

(self, strict: bool = True)

Source from the content-addressed store, hash-verified

425 self.content = text.encode(enc, "surrogateescape")
426
427 def get_text(self, strict: bool = True) -> str | None:
428 """
429 Similar to `Message.text`, but does not raise if `strict` is `False`.
430 Instead, the message body is returned as surrogate-escaped UTF-8.
431 """
432 content = self.get_content(strict)
433 if content is None:
434 return None
435 enc = infer_content_encoding(self.headers.get("content-type", ""), content)
436 try:
437 return cast(str, encoding.decode(content, enc))
438 except ValueError:
439 if strict:
440 raise
441 return content.decode("utf8", "surrogateescape")
442
443 @property
444 def timestamp_start(self) -> float:

Callers 8

textMethod · 0.95
test_unknown_ceMethod · 0.45
test_cannot_decodeMethod · 0.45
_get_urlencoded_formMethod · 0.45
_set_urlencoded_formMethod · 0.45
responseFunction · 0.45

Calls 4

get_contentMethod · 0.95
infer_content_encodingFunction · 0.90
getMethod · 0.45
decodeMethod · 0.45

Tested by 4

test_unknown_ceMethod · 0.36
test_cannot_decodeMethod · 0.36