MCPcopy Index your code
hub / github.com/python/cpython / add_header

Method add_header

Lib/wsgiref/headers.py:165–192  ·  view source on GitHub ↗

Extended header setting. _name is the header field to add. keyword arguments can be used to set additional parameters for the header field, with underscores converted to dashes. Normally the parameter will be added as key="value" unless value is None, in which case

(self, _name, _value, **_params)

Source from the content-addressed store, hash-verified

163 return result
164
165 def add_header(self, _name, _value, **_params):
166 """Extended header setting.
167
168 _name is the header field to add. keyword arguments can be used to set
169 additional parameters for the header field, with underscores converted
170 to dashes. Normally the parameter will be added as key="value" unless
171 value is None, in which case only the key will be added.
172
173 Example:
174
175 h.add_header('content-disposition', 'attachment', filename='bud.gif')
176
177 Note that unlike the corresponding 'email.message' method, this does
178 *not* handle '(charset, language, value)' tuples: all values must be
179 strings or None.
180 """
181 parts = []
182 if _value is not None:
183 _value = self._convert_string_type(_value, name=False)
184 parts.append(_value)
185 for k, v in _params.items():
186 k = self._convert_string_type(k, name=True)
187 if v is None:
188 parts.append(k.replace('_', '-'))
189 else:
190 v = self._convert_string_type(v, name=False)
191 parts.append(_formatparam(k.replace('_', '-'), v))
192 self._headers.append((self._convert_string_type(_name, name=True), "; ".join(parts)))

Callers 2

testExtrasMethod · 0.95

Calls 6

_convert_string_typeMethod · 0.95
_formatparamFunction · 0.70
appendMethod · 0.45
itemsMethod · 0.45
replaceMethod · 0.45
joinMethod · 0.45

Tested by 2

testExtrasMethod · 0.76