MCPcopy
hub / github.com/tornadoweb/tornado / add

Method add

tornado/httputil.py:210–228  ·  tornado/httputil.py::HTTPHeaders.add

Adds a new value for the given key.

(self, name: str, value: str, *, _chars_are_bytes: bool = True)

Source from the content-addressed store, hash-verified

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">""

Callers 15

handle_requestMethod · 0.95
__init__Method · 0.95
parse_lineMethod · 0.95
test_copyMethod · 0.95
test_pickle_roundtripMethod · 0.95
test_stringMethod · 0.95
fMethod · 0.95
bind_socketsFunction · 0.80
try_connectMethod · 0.80
watchFunction · 0.80
multi_futureFunction · 0.80

Calls 4

to_unicodeFunction · 0.90
HTTPInputErrorClass · 0.85
_normalize_headerFunction · 0.85
appendMethod · 0.80

Tested by 9

test_copyMethod · 0.76
test_pickle_roundtripMethod · 0.76
test_stringMethod · 0.76
fMethod · 0.76
innerFunction · 0.64
get_and_headMethod · 0.64
test_distinct_tokensMethod · 0.64
test_refresh_tokenMethod · 0.64