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

Method putrequest

Lib/http/client.py:1162–1287  ·  view source on GitHub ↗

Send a request to the server. 'method' specifies an HTTP request method, e.g. 'GET'. 'url' specifies the object being requested, e.g. '/index.html'. 'skip_host' if True does not add automatically a 'Host:' header 'skip_accept_encoding' if True does not add automatica

(self, method, url, skip_host=False,
                   skip_accept_encoding=False)

Source from the content-addressed store, hash-verified

1160 self.send(b'0\r\n\r\n')
1161
1162 def putrequest(self, method, url, skip_host=False,
1163 skip_accept_encoding=False):
1164 """Send a request to the server.
1165
1166 'method' specifies an HTTP request method, e.g. 'GET'.
1167 'url' specifies the object being requested, e.g. '/index.html'.
1168 'skip_host' if True does not add automatically a 'Host:' header
1169 'skip_accept_encoding' if True does not add automatically an
1170 'Accept-Encoding:' header
1171 """
1172
1173 # if a prior response has been completed, then forget about it.
1174 if self.__response and self.__response.isclosed():
1175 self.__response = None
1176
1177
1178 # in certain cases, we cannot issue another request on this connection.
1179 # this occurs when:
1180 # 1) we are in the process of sending a request. (_CS_REQ_STARTED)
1181 # 2) a response to a previous request has signalled that it is going
1182 # to close the connection upon completion.
1183 # 3) the headers for the previous response have not been read, thus
1184 # we cannot determine whether point (2) is true. (_CS_REQ_SENT)
1185 #
1186 # if there is no prior response, then we can request at will.
1187 #
1188 # if point (2) is true, then we will have passed the socket to the
1189 # response (effectively meaning, "there is no prior response"), and
1190 # will open a new one when a new request is made.
1191 #
1192 # Note: if a prior response exists, then we *can* start a new request.
1193 # We are not allowed to begin fetching the response to this new
1194 # request, however, until that prior response is complete.
1195 #
1196 if self.__state == _CS_IDLE:
1197 self.__state = _CS_REQ_STARTED
1198 else:
1199 raise CannotSendRequest(self.__state)
1200
1201 self._validate_method(method)
1202
1203 # Save the method for use later in the response phase
1204 self._method = method
1205
1206 url = url or '/'
1207 self._validate_path(url)
1208
1209 request = '%s %s %s' % (method, url, self._http_vsn_str)
1210
1211 self._output(self._encode_request(request))
1212
1213 if self._http_vsn == 11:
1214 # Issue some standard headers for better HTTP/1.1 compliance
1215
1216 if not skip_host:
1217 # this header is issued *only* for HTTP/1.1
1218 # connections. more specifically, this means it is
1219 # only issued when the client uses the new

Calls 13

_validate_methodMethod · 0.95
_validate_pathMethod · 0.95
_outputMethod · 0.95
_encode_requestMethod · 0.95
putheaderMethod · 0.95
_wrap_ipv6Method · 0.95
urlsplitFunction · 0.90
CannotSendRequestClass · 0.85
_strip_ipv6_ifaceFunction · 0.85
isclosedMethod · 0.80
startswithMethod · 0.45
encodeMethod · 0.45