MCPcopy Create free account
hub / github.com/mitmproxy/mitmproxy / __init__

Method __init__

mitmproxy/http.py:93–117  ·  view source on GitHub ↗

*Args:* - *fields:* (optional) list of ``(name, value)`` header byte tuples, e.g. ``[(b"Host", b"example.com")]``. All names and values must be bytes. - *\\*\\*headers:* Additional headers to set. Will overwrite existing values from `fields`. For conv

(self, fields: Iterable[tuple[bytes, bytes]] = (), **headers)

Source from the content-addressed store, hash-verified

91 """
92
93 def __init__(self, fields: Iterable[tuple[bytes, bytes]] = (), **headers):
94 """
95 *Args:*
96 - *fields:* (optional) list of ``(name, value)`` header byte tuples,
97 e.g. ``[(b"Host", b"example.com")]``. All names and values must be bytes.
98 - *\\*\\*headers:* Additional headers to set. Will overwrite existing values from `fields`.
99 For convenience, underscores in header names will be transformed to dashes -
100 this behaviour does not extend to other methods.
101
102 If ``**headers`` contains multiple keys that have equal ``.lower()`` representations,
103 the behavior is undefined.
104 """
105 super().__init__(fields)
106
107 for key, value in self.fields:
108 if not isinstance(key, bytes) or not isinstance(value, bytes):
109 raise TypeError("Header fields must be bytes.")
110
111 # content_type -> content-type
112 self.update(
113 {
114 _always_bytes(name).replace(b"_", b"-"): _always_bytes(value)
115 for name, value in headers.items()
116 }
117 )
118
119 fields: tuple[tuple[bytes, bytes], ...]
120

Callers

nothing calls this directly

Calls 4

_always_bytesFunction · 0.85
updateMethod · 0.45
replaceMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected