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

Method putheader

Lib/http/client.py:1318–1344  ·  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

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

_outputMethod · 0.95
CannotSendHeaderClass · 0.85
listClass · 0.85
enumerateFunction · 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