diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-09-16 18:44:34 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-09-16 18:44:34 +0200 |
commit | 9f26d68f47bc7729b0727ed67253503e047ea0f9 (patch) | |
tree | 50178b4346384ec12e2ae3fd41b508a06d68f1c8 /libpathod/pathoc.py | |
parent | b889e9e1a2576b0f0aadb4180dd6f4c75db204d6 (diff) | |
download | mitmproxy-9f26d68f47bc7729b0727ed67253503e047ea0f9.tar.gz mitmproxy-9f26d68f47bc7729b0727ed67253503e047ea0f9.tar.bz2 mitmproxy-9f26d68f47bc7729b0727ed67253503e047ea0f9.zip |
adjust to netlib changes
Diffstat (limited to 'libpathod/pathoc.py')
-rw-r--r-- | libpathod/pathoc.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index ac0b0e4d..c67fdb75 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -10,16 +10,18 @@ import time import threading import OpenSSL.crypto +import six from netlib import tcp, http, certutils, websockets, socks -from netlib.http import http1, http2 +from netlib.exceptions import HttpException +from netlib.http import http1, http2, ALPN_PROTO_HTTP1 import language.http import language.websockets from . import utils, log import logging -from netlib.http.http1 import HTTP1Protocol +from netlib.tutils import treq logging.getLogger("hpack").setLevel(logging.WARNING) @@ -213,7 +215,7 @@ class Pathoc(tcp.TCPClient): ) self.protocol = http2.HTTP2Protocol(self, dump_frames=self.http2_framedump) else: - self.protocol = http1.HTTP1Protocol(self) + self.protocol = http1 self.settings = language.Settings( is_client=True, @@ -229,15 +231,14 @@ class Pathoc(tcp.TCPClient): '\r\n' ) self.wfile.flush() - l = self.rfile.readline() - if not l: - raise PathocError("Proxy CONNECT failed") - parsed = self.protocol.parse_response_line(l) - if not parsed[1] == 200: - raise PathocError( - "Proxy CONNECT failed: %s - %s" % (parsed[1], parsed[2]) - ) - self.protocol.read_headers() + try: + resp = self.protocol.read_response(self.rfile, treq(method="CONNECT")) + if resp.status_code != 200: + raise HttpException("Unexpected status code: %s" % resp.status_code) + except HttpException as e: + six.reraise(PathocError, PathocError( + "Proxy CONNECT failed: %s" % repr(e) + )) def socks_connect(self, connect_to): try: @@ -288,9 +289,9 @@ class Pathoc(tcp.TCPClient): self.sslinfo = None if self.ssl: try: - alpn_protos = [HTTP1Protocol.ALPN_PROTO_HTTP1] + alpn_protos = [ALPN_PROTO_HTTP1] if self.use_http2: - alpn_protos.append(http2.HTTP2Protocol.ALPN_PROTO_H2) + alpn_protos.append(http.ALPN_PROTO_H2) self.convert_to_ssl( sni=self.sni, @@ -408,9 +409,9 @@ class Pathoc(tcp.TCPClient): req = language.serve(r, self.wfile, self.settings) self.wfile.flush() - resp = self.protocol.read_response(req["method"], None) + resp = self.protocol.read_response(self.rfile, treq(method=req["method"])) resp.sslinfo = self.sslinfo - except http.HttpError as v: + except HttpException as v: lg("Invalid server response: %s" % v) raise except tcp.NetLibTimeout: |