MCPcopy Index your code
hub / github.com/RustPython/RustPython / putheader

Method putheader

Lib/http/client.py:1314–1340  ·  view source on GitHub ↗

Send a request header line to the server. For example: h.putheader('Accept', 'text/html')

(self, header, *values)

Source from the content-addressed store, hash-verified

1312 f"(found at least {match.group()!r})")
1313
1314 def putheader(self, header, *values):
1315 """Send a request header line to the server.
1316
1317 For example: h.putheader('Accept', 'text/html')
1318 """
1319 if self.__state != _CS_REQ_STARTED:
1320 raise CannotSendHeader()
1321
1322 if hasattr(header, 'encode'):
1323 header = header.encode('ascii')
1324
1325 if not _is_legal_header_name(header):
1326 raise ValueError('Invalid header name %r' % (header,))
1327
1328 values = list(values)
1329 for i, one_value in enumerate(values):
1330 if hasattr(one_value, 'encode'):
1331 values[i] = one_value.encode('latin-1')
1332 elif isinstance(one_value, int):
1333 values[i] = str(one_value).encode('ascii')
1334
1335 if _is_illegal_header_value(values[i]):
1336 raise ValueError('Invalid header value %r' % (values[i],))
1337
1338 value = b'\r\n\t'.join(values)
1339 header = header + b': ' + value
1340 self._output(header)
1341
1342 def endheaders(self, message_body=None, *, encode_chunked=False):
1343 """Indicate that the last header line has been sent to the server.

Callers 10

putrequestMethod · 0.95
_send_requestMethod · 0.95
test_putheaderMethod · 0.95
test_invalid_headersMethod · 0.95
emitMethod · 0.80
send_contentMethod · 0.80
test_header_closeMethod · 0.80
send_headersMethod · 0.80
send_contentMethod · 0.80

Calls 9

_outputMethod · 0.95
CannotSendHeaderClass · 0.85
hasattrFunction · 0.85
listClass · 0.85
enumerateFunction · 0.85
isinstanceFunction · 0.85
strFunction · 0.85
encodeMethod · 0.45
joinMethod · 0.45

Tested by 5

test_putheaderMethod · 0.76
test_invalid_headersMethod · 0.76
send_contentMethod · 0.64
test_header_closeMethod · 0.64