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

Method set_text

mitmproxy/http.py:407–425  ·  view source on GitHub ↗
(self, text: str | None)

Source from the content-addressed store, hash-verified

405 return self.raw_content
406
407 def set_text(self, text: str | None) -> None:
408 if text is None:
409 self.content = None
410 return
411 enc = infer_content_encoding(self.headers.get("content-type", ""))
412
413 try:
414 self.content = cast(bytes, encoding.encode(text, enc))
415 except ValueError:
416 # Fall back to UTF-8 and update the content-type header.
417 ct = parse_content_type(self.headers.get("content-type", "")) or (
418 "text",
419 "plain",
420 {},
421 )
422 ct[2]["charset"] = "utf-8"
423 self.headers["content-type"] = assemble_content_type(*ct)
424 enc = "utf8"
425 self.content = text.encode(enc, "surrogateescape")
426
427 def get_text(self, strict: bool = True) -> str | None:
428 """

Callers 1

textMethod · 0.95

Calls 5

infer_content_encodingFunction · 0.90
parse_content_typeFunction · 0.90
assemble_content_typeFunction · 0.90
getMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected