Show More
@@ -222,47 +222,6 b' def _generic_start_transaction(handler, ' | |||||
222 | h.headers = None |
|
222 | h.headers = None | |
223 |
|
223 | |||
224 |
|
224 | |||
225 | def _generic_proxytunnel(self: "httpsconnection"): |
|
|||
226 | headers = self.headers # pytype: disable=attribute-error |
|
|||
227 | proxyheaders = { |
|
|||
228 | pycompat.bytestr(x): pycompat.bytestr(headers[x]) |
|
|||
229 | for x in headers |
|
|||
230 | if x.lower().startswith('proxy-') |
|
|||
231 | } |
|
|||
232 | realhostport = self.realhostport # pytype: disable=attribute-error |
|
|||
233 | self.send(b'CONNECT %s HTTP/1.0\r\n' % realhostport) |
|
|||
234 |
|
||||
235 | for header in proxyheaders.items(): |
|
|||
236 | self.send(b'%s: %s\r\n' % header) |
|
|||
237 | self.send(b'\r\n') |
|
|||
238 |
|
||||
239 | # majority of the following code is duplicated from |
|
|||
240 | # httplib.HTTPConnection as there are no adequate places to |
|
|||
241 | # override functions to provide the needed functionality. |
|
|||
242 |
|
||||
243 | # pytype: disable=attribute-error |
|
|||
244 | res = self.response_class(self.sock, method=self._method) |
|
|||
245 | # pytype: enable=attribute-error |
|
|||
246 |
|
||||
247 | while True: |
|
|||
248 | # pytype: disable=attribute-error |
|
|||
249 | version, status, reason = res._read_status() |
|
|||
250 | # pytype: enable=attribute-error |
|
|||
251 | if status != httplib.CONTINUE: |
|
|||
252 | break |
|
|||
253 | # skip lines that are all whitespace |
|
|||
254 | list(iter(lambda: res.fp.readline().strip(), b'')) |
|
|||
255 |
|
||||
256 | if status == 200: |
|
|||
257 | # skip lines until we find a blank line |
|
|||
258 | list(iter(res.fp.readline, b'\r\n')) |
|
|||
259 | else: |
|
|||
260 | self.close() |
|
|||
261 | raise socket.error( |
|
|||
262 | "Tunnel connection failed: %d %s" % (status, reason.strip()) |
|
|||
263 | ) |
|
|||
264 |
|
||||
265 |
|
||||
266 | class httphandler(keepalive.HTTPHandler): |
|
225 | class httphandler(keepalive.HTTPHandler): | |
267 | def http_open(self, req): |
|
226 | def http_open(self, req): | |
268 | return self.do_open(httpconnection, req) |
|
227 | return self.do_open(httpconnection, req) | |
@@ -306,6 +265,46 b' class logginghttphandler(httphandler):' | |||||
306 |
|
265 | |||
307 | if has_https: |
|
266 | if has_https: | |
308 |
|
267 | |||
|
268 | def _generic_proxytunnel(self: "httpsconnection"): | |||
|
269 | headers = self.headers # pytype: disable=attribute-error | |||
|
270 | proxyheaders = { | |||
|
271 | pycompat.bytestr(x): pycompat.bytestr(headers[x]) | |||
|
272 | for x in headers | |||
|
273 | if x.lower().startswith('proxy-') | |||
|
274 | } | |||
|
275 | realhostport = self.realhostport # pytype: disable=attribute-error | |||
|
276 | self.send(b'CONNECT %s HTTP/1.0\r\n' % realhostport) | |||
|
277 | ||||
|
278 | for header in proxyheaders.items(): | |||
|
279 | self.send(b'%s: %s\r\n' % header) | |||
|
280 | self.send(b'\r\n') | |||
|
281 | ||||
|
282 | # majority of the following code is duplicated from | |||
|
283 | # httplib.HTTPConnection as there are no adequate places to | |||
|
284 | # override functions to provide the needed functionality. | |||
|
285 | ||||
|
286 | # pytype: disable=attribute-error | |||
|
287 | res = self.response_class(self.sock, method=self._method) | |||
|
288 | # pytype: enable=attribute-error | |||
|
289 | ||||
|
290 | while True: | |||
|
291 | # pytype: disable=attribute-error | |||
|
292 | version, status, reason = res._read_status() | |||
|
293 | # pytype: enable=attribute-error | |||
|
294 | if status != httplib.CONTINUE: | |||
|
295 | break | |||
|
296 | # skip lines that are all whitespace | |||
|
297 | list(iter(lambda: res.fp.readline().strip(), b'')) | |||
|
298 | ||||
|
299 | if status == 200: | |||
|
300 | # skip lines until we find a blank line | |||
|
301 | list(iter(res.fp.readline, b'\r\n')) | |||
|
302 | else: | |||
|
303 | self.close() | |||
|
304 | raise socket.error( | |||
|
305 | "Tunnel connection failed: %d %s" % (status, reason.strip()) | |||
|
306 | ) | |||
|
307 | ||||
309 | class httpsconnection(keepalive.HTTPConnection): |
|
308 | class httpsconnection(keepalive.HTTPConnection): | |
310 | response_class = keepalive.HTTPResponse |
|
309 | response_class = keepalive.HTTPResponse | |
311 | default_port = httplib.HTTPS_PORT |
|
310 | default_port = httplib.HTTPS_PORT |
General Comments 0
You need to be logged in to leave comments.
Login now