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

Function _test_decoded_attr

test/mitmproxy/test_http.py:876–900  ·  view source on GitHub ↗
(message, attr)

Source from the content-addressed store, hash-verified

874
875
876def _test_decoded_attr(message, attr):
877 assert getattr(message, attr) == getattr(message.data, attr).decode("utf8")
878 # Set str, get raw bytes
879 setattr(message, attr, "foo")
880 assert getattr(message.data, attr) == b"foo"
881 # Set raw bytes, get decoded
882 setattr(
883 message.data, attr, b"BAR"
884 ) # use uppercase so that we can also cover request.method
885 assert getattr(message, attr) == "BAR"
886 # Set bytes, get raw bytes
887 setattr(message, attr, b"baz")
888 assert getattr(message.data, attr) == b"baz"
889
890 # Set UTF8
891 setattr(message, attr, "Non-Autorisé")
892 assert getattr(message.data, attr) == b"Non-Autoris\xc3\xa9"
893 # Don't fail on garbage
894 setattr(message.data, attr, b"FOO\xbf\x00BAR")
895 assert getattr(message, attr).startswith("FOO")
896 assert getattr(message, attr).endswith("BAR")
897 # foo.bar = foo.bar should not cause any side effects.
898 d = getattr(message, attr)
899 setattr(message, attr, d)
900 assert getattr(message.data, attr) == b"FOO\xbf\x00BAR"
901
902
903class TestMessageData:

Callers 4

test_methodMethod · 0.85
test_schemeMethod · 0.85
test_pathMethod · 0.85
test_http_versionMethod · 0.85

Calls 1

decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…