remove treq from pathoc
Using a function intended only for tests in active live code is ugly. However, this whole portion of pathoc could benefit from some further improvements.
This commit is contained in:
parent
f77cf03543
commit
4771c9599e
|
@ -11,15 +11,14 @@ import time
|
||||||
import OpenSSL.crypto
|
import OpenSSL.crypto
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from mitmproxy.test.tutils import treq
|
|
||||||
from mitmproxy.utils import strutils
|
|
||||||
from mitmproxy.net import tcp
|
|
||||||
from mitmproxy import certs
|
from mitmproxy import certs
|
||||||
|
from mitmproxy import exceptions
|
||||||
|
from mitmproxy.net import tcp
|
||||||
from mitmproxy.net import websockets
|
from mitmproxy.net import websockets
|
||||||
from mitmproxy.net import socks
|
from mitmproxy.net import socks
|
||||||
from mitmproxy import exceptions
|
from mitmproxy.net import http as net_http
|
||||||
from mitmproxy.net.http import http1
|
|
||||||
from mitmproxy.types import basethread
|
from mitmproxy.types import basethread
|
||||||
|
from mitmproxy.utils import strutils
|
||||||
|
|
||||||
from pathod import log
|
from pathod import log
|
||||||
from pathod import language
|
from pathod import language
|
||||||
|
@ -234,7 +233,7 @@ class Pathoc(tcp.TCPClient):
|
||||||
)
|
)
|
||||||
self.protocol = http2.HTTP2StateProtocol(self, dump_frames=self.http2_framedump)
|
self.protocol = http2.HTTP2StateProtocol(self, dump_frames=self.http2_framedump)
|
||||||
else:
|
else:
|
||||||
self.protocol = http1
|
self.protocol = net_http.http1
|
||||||
|
|
||||||
self.settings = language.Settings(
|
self.settings = language.Settings(
|
||||||
is_client=True,
|
is_client=True,
|
||||||
|
@ -245,13 +244,20 @@ class Pathoc(tcp.TCPClient):
|
||||||
)
|
)
|
||||||
|
|
||||||
def http_connect(self, connect_to):
|
def http_connect(self, connect_to):
|
||||||
self.wfile.write(
|
req = net_http.Request(
|
||||||
b'CONNECT %s:%d HTTP/1.1\r\n' % (connect_to[0].encode("idna"), connect_to[1]) +
|
first_line_format='authority',
|
||||||
b'\r\n'
|
method='CONNECT',
|
||||||
|
scheme=None,
|
||||||
|
host=connect_to[0].encode("idna"),
|
||||||
|
port=connect_to[1],
|
||||||
|
path=None,
|
||||||
|
http_version='HTTP/1.1',
|
||||||
|
content=b'',
|
||||||
)
|
)
|
||||||
|
self.wfile.write(net_http.http1.assemble_request(req))
|
||||||
self.wfile.flush()
|
self.wfile.flush()
|
||||||
try:
|
try:
|
||||||
resp = self.protocol.read_response(self.rfile, treq(method=b"CONNECT"))
|
resp = self.protocol.read_response(self.rfile, req)
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
raise exceptions.HttpException("Unexpected status code: %s" % resp.status_code)
|
raise exceptions.HttpException("Unexpected status code: %s" % resp.status_code)
|
||||||
except exceptions.HttpException as e:
|
except exceptions.HttpException as e:
|
||||||
|
@ -435,7 +441,20 @@ class Pathoc(tcp.TCPClient):
|
||||||
req = language.serve(r, self.wfile, self.settings)
|
req = language.serve(r, self.wfile, self.settings)
|
||||||
self.wfile.flush()
|
self.wfile.flush()
|
||||||
|
|
||||||
resp = self.protocol.read_response(self.rfile, treq(method=req["method"].encode()))
|
# build a dummy request to read the reponse
|
||||||
|
# ideally this would be returned directly from language.serve
|
||||||
|
dummy_req = net_http.Request(
|
||||||
|
first_line_format="relative",
|
||||||
|
method=req["method"],
|
||||||
|
scheme=b"http",
|
||||||
|
host=b"localhost",
|
||||||
|
port=80,
|
||||||
|
path=b"/",
|
||||||
|
http_version=b"HTTP/1.1",
|
||||||
|
content=b'',
|
||||||
|
)
|
||||||
|
|
||||||
|
resp = self.protocol.read_response(self.rfile, dummy_req)
|
||||||
resp.sslinfo = self.sslinfo
|
resp.sslinfo = self.sslinfo
|
||||||
except exceptions.HttpException as v:
|
except exceptions.HttpException as v:
|
||||||
lg("Invalid server response: %s" % v)
|
lg("Invalid server response: %s" % v)
|
||||||
|
|
Loading…
Reference in New Issue