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

Method do_request_

Lib/urllib/request.py:1244–1280  ·  view source on GitHub ↗
(self, request)

Source from the content-addressed store, hash-verified

1242 request.get_method())
1243
1244 def do_request_(self, request):
1245 host = request.host
1246 if not host:
1247 raise URLError('no host given')
1248
1249 if request.data is not None: # POST
1250 data = request.data
1251 if isinstance(data, str):
1252 msg = "POST data should be bytes, an iterable of bytes, " \
1253 "or a file object. It cannot be of type str."
1254 raise TypeError(msg)
1255 if not request.has_header('Content-type'):
1256 request.add_unredirected_header(
1257 'Content-type',
1258 'application/x-www-form-urlencoded')
1259 if (not request.has_header('Content-length')
1260 and not request.has_header('Transfer-encoding')):
1261 content_length = self._get_content_length(request)
1262 if content_length is not None:
1263 request.add_unredirected_header(
1264 'Content-length', str(content_length))
1265 else:
1266 request.add_unredirected_header(
1267 'Transfer-encoding', 'chunked')
1268
1269 sel_host = host
1270 if request.has_proxy():
1271 scheme, sel = _splittype(request.selector)
1272 sel_host, sel_path = _splithost(sel)
1273 if not request.has_header('Host'):
1274 request.add_unredirected_header('Host', sel_host)
1275 for name, value in self.parent.addheaders:
1276 name = name.capitalize()
1277 if not request.has_header(name):
1278 request.add_unredirected_header(name, value)
1279
1280 return request
1281
1282 def do_open(self, http_class, req, **http_conn_args):
1283 """Return an HTTPResponse object for the request, using http_class.

Callers 9

test_httpMethod · 0.95
test_http_body_fileMethod · 0.95
test_http_body_pipeMethod · 0.95
test_http_body_arrayMethod · 0.95
test_http_doubleslashMethod · 0.95

Calls 9

_get_content_lengthMethod · 0.95
URLErrorClass · 0.90
_splittypeFunction · 0.90
_splithostFunction · 0.90
strFunction · 0.85
has_proxyMethod · 0.80
has_headerMethod · 0.45
capitalizeMethod · 0.45

Tested by 9

test_httpMethod · 0.76
test_http_body_fileMethod · 0.76
test_http_body_pipeMethod · 0.76
test_http_body_arrayMethod · 0.76
test_http_doubleslashMethod · 0.76