From fbc4bb38df48447f846ae0ff4f87062c827bd632 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 8 Sep 2014 23:34:43 +0200 Subject: mitmproxy -> libmproxy.main. do some leanup on the way --- libmproxy/proxy/__init__.py | 2 +- libmproxy/proxy/config.py | 11 +++++++++-- libmproxy/proxy/server.py | 13 +++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) (limited to 'libmproxy/proxy') diff --git a/libmproxy/proxy/__init__.py b/libmproxy/proxy/__init__.py index e4c20030..f33d323b 100644 --- a/libmproxy/proxy/__init__.py +++ b/libmproxy/proxy/__init__.py @@ -1,2 +1,2 @@ from .primitives import * -from .config import ProxyConfig +from .config import ProxyConfig, process_proxy_options diff --git a/libmproxy/proxy/config.py b/libmproxy/proxy/config.py index 441e05f1..62104a24 100644 --- a/libmproxy/proxy/config.py +++ b/libmproxy/proxy/config.py @@ -2,7 +2,7 @@ from __future__ import absolute_import import os import re from netlib import http_auth, certutils -from .. import utils, platform +from .. import utils, platform, version from .primitives import RegularProxyMode, TransparentProxyMode, UpstreamProxyMode, ReverseProxyMode TRANSPARENT_SSL_PORTS = [443, 8443] @@ -15,11 +15,15 @@ def parse_host_pattern(patterns): class ProxyConfig: - def __init__(self, confdir=CONF_DIR, ca_file=None, clientcerts=None, + def __init__(self, host='', port=8080, server_version=version.NAMEVERSION, + confdir=CONF_DIR, ca_file=None, clientcerts=None, no_upstream_cert=False, body_size_limit=None, mode=None, upstream_server=None, http_form_in=None, http_form_out=None, authenticator=None, ignore=[], ciphers=None, certs=[], certforward=False, ssl_ports=TRANSPARENT_SSL_PORTS): + self.host = host + self.port = port + self.server_version = server_version self.ciphers = ciphers self.clientcerts = clientcerts self.no_upstream_cert = no_upstream_cert @@ -34,6 +38,7 @@ class ProxyConfig: else: self.mode = RegularProxyMode() + # Handle manual overrides of the http forms self.mode.http_form_in = http_form_in or self.mode.http_form_in self.mode.http_form_out = http_form_out or self.mode.http_form_out @@ -105,6 +110,8 @@ def process_proxy_options(parser, options): certs.append(parts) return ProxyConfig( + host=options.addr, + port=options.port, confdir=options.confdir, clientcerts=options.clientcerts, no_upstream_cert=options.no_upstream_cert, diff --git a/libmproxy/proxy/server.py b/libmproxy/proxy/server.py index f4a978ca..307a4bcd 100644 --- a/libmproxy/proxy/server.py +++ b/libmproxy/proxy/server.py @@ -27,14 +27,13 @@ class ProxyServer(tcp.TCPServer): allow_reuse_address = True bound = True - def __init__(self, config, port, host='', server_version=version.NAMEVERSION): + def __init__(self, config): """ Raises ProxyServerError if there's a startup problem. """ self.config = config - self.server_version = server_version try: - tcp.TCPServer.__init__(self, (host, port)) + tcp.TCPServer.__init__(self, (config.host, config.port)) except socket.error, v: raise ProxyServerError('Error starting proxy server: ' + repr(v)) self.channel = None @@ -47,22 +46,20 @@ class ProxyServer(tcp.TCPServer): self.channel = channel def handle_client_connection(self, conn, client_address): - h = ConnectionHandler(self.config, conn, client_address, self, self.channel, - self.server_version) + h = ConnectionHandler(self.config, conn, client_address, self, self.channel) h.handle() h.finish() class ConnectionHandler: - def __init__(self, config, client_connection, client_address, server, channel, - server_version): + def __init__(self, config, client_connection, client_address, server, channel): self.config = config """@type: libmproxy.proxy.config.ProxyConfig""" self.client_conn = ClientConnection(client_connection, client_address, server) """@type: libmproxy.proxy.connection.ClientConnection""" self.server_conn = None """@type: libmproxy.proxy.connection.ServerConnection""" - self.channel, self.server_version = channel, server_version + self.channel = channel self.conntype = "http" self.sni = None -- cgit v1.2.3