From 2d4a5fb116a175df0d464e9a501124a858731d99 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 18 Sep 2015 18:07:38 +0200 Subject: experimental: don't interfere with headers, fix #93 --- libmproxy/flow.py | 2 +- libmproxy/models/http.py | 1 - libmproxy/protocol/__init__.py | 4 ++-- libmproxy/protocol/http_replay.py | 4 ++++ libmproxy/proxy/root_context.py | 5 +++-- 5 files changed, 10 insertions(+), 6 deletions(-) (limited to 'libmproxy') diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 8ee017f6..7d51b6d1 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -922,7 +922,7 @@ class FlowMaster(controller.Master): if f.request: f.backup() f.request.is_replay = True - if f.request.content: + if "Content-Length" in f.request.headers: f.request.headers["Content-Length"] = str(len(f.request.content)) f.response = None f.error = None diff --git a/libmproxy/models/http.py b/libmproxy/models/http.py index 7e46c834..c0a2c55a 100644 --- a/libmproxy/models/http.py +++ b/libmproxy/models/http.py @@ -549,7 +549,6 @@ def make_connect_request(address): def make_connect_response(http_version): headers = Headers( - Content_Length="0", Proxy_Agent=version.NAMEVERSION ) return HTTPResponse( diff --git a/libmproxy/protocol/__init__.py b/libmproxy/protocol/__init__.py index 35d59f28..0d624fd7 100644 --- a/libmproxy/protocol/__init__.py +++ b/libmproxy/protocol/__init__.py @@ -27,13 +27,13 @@ as late as possible; this makes server replay without any outgoing connections p from __future__ import (absolute_import, print_function, division) from .base import Layer, ServerConnectionMixin, Kill -from .http import Http1Layer, Http2Layer +from .http import Http1Layer, UpstreamConnectLayer, Http2Layer from .tls import TlsLayer, is_tls_record_magic from .rawtcp import RawTCPLayer __all__ = [ "Layer", "ServerConnectionMixin", "Kill", - "Http1Layer", "Http2Layer", + "Http1Layer", "UpstreamConnectLayer", "Http2Layer", "TlsLayer", "is_tls_record_magic", "RawTCPLayer" ] diff --git a/libmproxy/protocol/http_replay.py b/libmproxy/protocol/http_replay.py index 00b0b82b..14fbe547 100644 --- a/libmproxy/protocol/http_replay.py +++ b/libmproxy/protocol/http_replay.py @@ -1,5 +1,6 @@ from __future__ import (absolute_import, print_function, division) import threading +import traceback from libmproxy.exceptions import ReplayException from netlib.exceptions import HttpException, TcpException from netlib.http import http1 @@ -97,5 +98,8 @@ class RequestReplayThread(threading.Thread): # first place. from ..proxy.root_context import Log self.channel.tell("log", Log("Connection killed", "info")) + except Exception: + from ..proxy.root_context import Log + self.channel.tell("log", Log(traceback.format_exc(), "error")) finally: r.form_out = form_out_backup diff --git a/libmproxy/proxy/root_context.py b/libmproxy/proxy/root_context.py index 48cb72a0..307d0c4b 100644 --- a/libmproxy/proxy/root_context.py +++ b/libmproxy/proxy/root_context.py @@ -8,7 +8,8 @@ from libmproxy.exceptions import ProtocolException from netlib.exceptions import TcpException from netlib.http import ALPN_PROTO_H2, ALPN_PROTO_HTTP1 from ..protocol import ( - RawTCPLayer, TlsLayer, Http1Layer, Http2Layer, is_tls_record_magic, ServerConnectionMixin + RawTCPLayer, TlsLayer, Http1Layer, Http2Layer, is_tls_record_magic, ServerConnectionMixin, + UpstreamConnectLayer ) from .modes import HttpProxy, HttpUpstreamProxy, ReverseProxy @@ -63,7 +64,7 @@ class RootContext(object): # in which case we need some form of TLS layer. if isinstance(top_layer, ReverseProxy): return TlsLayer(top_layer, client_tls, top_layer.server_tls) - if isinstance(top_layer, ServerConnectionMixin): + if isinstance(top_layer, ServerConnectionMixin) or isinstance(top_layer, UpstreamConnectLayer): return TlsLayer(top_layer, client_tls, client_tls) # 3. In Http Proxy mode and Upstream Proxy mode, the next layer is fixed. -- cgit v1.2.3