Adds a new value for the given key.
(self, name: str, value: str, *, _chars_are_bytes: bool = True)
| 208 | class="cm"># new public methods |
| 209 | |
| 210 | def add(self, name: str, value: str, *, _chars_are_bytes: bool = True) -> None: |
| 211 | class="st">""class="st">"Adds a new value for the given key."class="st">"" |
| 212 | if not _ABNF.field_name.fullmatch(name): |
| 213 | raise HTTPInputError(class="st">"Invalid header name %r" % name) |
| 214 | if _chars_are_bytes: |
| 215 | if not _ABNF.field_value.fullmatch(to_unicode(value)): |
| 216 | class="cm"># TODO: the fact we still support bytes here (contrary to type annotations) |
| 217 | class="cm"># and still test for it should probably be changed. |
| 218 | raise HTTPInputError(class="st">"Invalid header value %r" % value) |
| 219 | else: |
| 220 | if _FORBIDDEN_HEADER_CHARS_RE.search(value): |
| 221 | raise HTTPInputError(class="st">"Invalid header value %r" % value) |
| 222 | norm_name = _normalize_header(name) |
| 223 | self._last_key = norm_name |
| 224 | if norm_name in self: |
| 225 | self._combined_cache.pop(norm_name, None) |
| 226 | self._as_list[norm_name].append(value) |
| 227 | else: |
| 228 | self[norm_name] = value |
| 229 | |
| 230 | def get_list(self, name: str) -> List[str]: |
| 231 | class="st">""class="st">"Returns all values for the given header as a list."class="st">"" |