MCPcopy
hub / github.com/mitmproxy/mitmproxy / get_content

Method get_content

mitmproxy/http.py:385–405  ·  view source on GitHub ↗

Similar to `Message.content`, but does not raise if `strict` is `False`. Instead, the compressed message body is returned as-is.

(self, strict: bool = True)

Source from the content-addressed store, hash-verified

383 self.headers["content-length"] = str(len(self.raw_content))
384
385 def get_content(self, strict: bool = True) -> bytes | None:
386 """
387 Similar to `Message.content`, but does not raise if `strict` is `False`.
388 Instead, the compressed message body is returned as-is.
389 """
390 if self.raw_content is None:
391 return None
392 ce = self.headers.get("content-encoding")
393 if ce:
394 try:
395 content = encoding.decode(self.raw_content, ce)
396 # A client may illegally specify a byte -> str encoding here (e.g. utf8)
397 if isinstance(content, str):
398 raise ValueError(f"Invalid Content-Encoding: {ce}")
399 return content
400 except ValueError:
401 if strict:
402 raise
403 return self.raw_content
404 else:
405 return self.raw_content
406
407 def set_text(self, text: str | None) -> None:
408 if text is None:

Callers 13

contentMethod · 0.95
get_textMethod · 0.95
decodeMethod · 0.95
jsonMethod · 0.95
test_unknown_ceMethod · 0.80
test_utf8_as_ceMethod · 0.80
test_cannot_decodeMethod · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
bodyviewMethod · 0.80
edit_focusMethod · 0.80

Calls 2

getMethod · 0.45
decodeMethod · 0.45

Tested by 3

test_unknown_ceMethod · 0.64
test_utf8_as_ceMethod · 0.64
test_cannot_decodeMethod · 0.64