|
90 | 90 | "synapse_http_client_responses", "", ["method", "code"]
|
91 | 91 | )
|
92 | 92 |
|
93 |
| -# the type of the headers list, to be passed to the t.w.h.Headers. |
94 |
| -# Actually we can mix str and bytes keys, but Mapping treats 'key' as invariant so |
95 |
| -# we simplify. |
| 93 | +# the type of the headers map, to be passed to the t.w.h.Headers. |
| 94 | +# |
| 95 | +# The actual type accepted by Twisted is |
| 96 | +# Mapping[Union[str, bytes], Sequence[Union[str, bytes]] , |
| 97 | +# allowing us to mix and match str and bytes freely. However: any str is also a |
| 98 | +# Sequence[str]; passing a header string value which is a |
| 99 | +# standalone str is interpreted as a sequence of 1-codepoint strings. This is a disastrous footgun. |
| 100 | +# We use a narrower value type (RawHeaderValue) to avoid this footgun. |
| 101 | +# |
| 102 | +# We also simplify the keys to be either all str or all bytes. This helps because |
| 103 | +# Dict[K, V] is invariant in K (and indeed V). |
96 | 104 | RawHeaders = Union[Mapping[str, "RawHeaderValue"], Mapping[bytes, "RawHeaderValue"]]
|
97 | 105 |
|
98 | 106 | # the value actually has to be a List, but List is invariant so we can't specify that
|
99 | 107 | # the entries can either be Lists or bytes.
|
100 |
| -RawHeaderValue = Sequence[Union[str, bytes]] |
| 108 | +RawHeaderValue = Union[ |
| 109 | + List[str], |
| 110 | + List[bytes], |
| 111 | + List[Union[str, bytes]], |
| 112 | + Tuple[str, ...], |
| 113 | + Tuple[bytes, ...], |
| 114 | + Tuple[Union[str, bytes], ...], |
| 115 | +] |
101 | 116 |
|
102 | 117 |
|
103 | 118 | def check_against_blacklist(
|
|
0 commit comments