mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-01-31 07:18:58 +00:00
Allow control of buffer size for TCPClient, improve error messages.
This commit is contained in:
parent
7480f87cd7
commit
67669a2a57
@ -260,15 +260,15 @@ def read_response(rfile, method, body_size_limit):
|
||||
if len(parts) == 2: # handle missing message gracefully
|
||||
parts.append("")
|
||||
if not len(parts) == 3:
|
||||
raise HttpError(502, "Invalid server response: %s."%line)
|
||||
raise HttpError(502, "Invalid server response: %s"%repr(line))
|
||||
proto, code, msg = parts
|
||||
httpversion = parse_http_protocol(proto)
|
||||
if httpversion is None:
|
||||
raise HttpError(502, "Invalid HTTP version: %s."%httpversion)
|
||||
raise HttpError(502, "Invalid HTTP version: %s"%repr(httpversion))
|
||||
try:
|
||||
code = int(code)
|
||||
except ValueError:
|
||||
raise HttpError(502, "Invalid server response: %s."%line)
|
||||
raise HttpError(502, "Invalid server response: %s"%repr(line))
|
||||
headers = read_headers(rfile)
|
||||
if code >= 100 and code <= 199:
|
||||
return read_response(rfile, method, body_size_limit)
|
||||
|
@ -50,6 +50,8 @@ class FileLike:
|
||||
|
||||
|
||||
class TCPClient:
|
||||
rbufsize = -1
|
||||
wbufsize = -1
|
||||
def __init__(self, host, port):
|
||||
self.host, self.port = host, port
|
||||
self.connection, self.rfile, self.wfile = None, None, None
|
||||
@ -78,7 +80,8 @@ class TCPClient:
|
||||
addr = socket.gethostbyname(self.host)
|
||||
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
connection.connect((addr, self.port))
|
||||
self.rfile, self.wfile = connection.makefile('rb'), connection.makefile('wb')
|
||||
self.rfile = connection.makefile('rb', self.rbufsize)
|
||||
self.wfile = connection.makefile('wb', self.wbufsize)
|
||||
except socket.error, err:
|
||||
raise NetLibError('Error connecting to "%s": %s' % (self.host, err))
|
||||
self.connection = connection
|
||||
|
Loading…
Reference in New Issue
Block a user