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

Method _send_request

Lib/http/client.py:1360–1404  ·  view source on GitHub ↗
(self, method, url, body, headers, encode_chunked)

Source from the content-addressed store, hash-verified

1358 self._send_request(method, url, body, headers, encode_chunked)
1359
1360 def _send_request(self, method, url, body, headers, encode_chunked):
1361 # Honor explicitly requested Host: and Accept-Encoding: headers.
1362 header_names = frozenset(k.lower() for k in headers)
1363 skips = {}
1364 if 'host' in header_names:
1365 skips['skip_host'] = 1
1366 if 'accept-encoding' in header_names:
1367 skips['skip_accept_encoding'] = 1
1368
1369 self.putrequest(method, url, **skips)
1370
1371 # chunked encoding will happen if HTTP/1.1 is used and either
1372 # the caller passes encode_chunked=True or the following
1373 # conditions hold:
1374 # 1. content-length has not been explicitly set
1375 # 2. the body is a file or iterable, but not a str or bytes-like
1376 # 3. Transfer-Encoding has NOT been explicitly set by the caller
1377
1378 if 'content-length' not in header_names:
1379 # only chunk body if not explicitly set for backwards
1380 # compatibility, assuming the client code is already handling the
1381 # chunking
1382 if 'transfer-encoding' not in header_names:
1383 # if content-length cannot be automatically determined, fall
1384 # back to chunked encoding
1385 encode_chunked = False
1386 content_length = self._get_content_length(body, method)
1387 if content_length is None:
1388 if body is not None:
1389 if self.debuglevel > 0:
1390 print('Unable to determine size of %r' % body)
1391 encode_chunked = True
1392 self.putheader('Transfer-Encoding', 'chunked')
1393 else:
1394 self.putheader('Content-Length', str(content_length))
1395 else:
1396 encode_chunked = False
1397
1398 for hdr, value in headers.items():
1399 self.putheader(hdr, value)
1400 if isinstance(body, str):
1401 # RFC 2616 Section 3.7.1 says that text default has a
1402 # default charset of iso-8859-1.
1403 body = _encode(body, 'body')
1404 self.endheaders(body, encode_chunked=encode_chunked)
1405
1406 def getresponse(self):
1407 """Get the response from the server.

Callers 1

requestMethod · 0.95

Calls 10

putrequestMethod · 0.95
_get_content_lengthMethod · 0.95
putheaderMethod · 0.95
endheadersMethod · 0.95
strFunction · 0.85
isinstanceFunction · 0.85
_encodeFunction · 0.70
printFunction · 0.50
lowerMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected