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