minor fixes

This commit is contained in:
Maximilian Hils 2015-08-16 12:43:15 +02:00
parent a175572447
commit 4c31ffd90f
3 changed files with 48 additions and 47 deletions

View File

@ -12,9 +12,10 @@ from libmproxy.protocol.http_wrappers import HTTPResponse, HTTPRequest
from libmproxy.protocol2.http_protocol_mock import HTTP1 from libmproxy.protocol2.http_protocol_mock import HTTP1
from libmproxy.protocol2.tls import TlsLayer from libmproxy.protocol2.tls import TlsLayer
from netlib import tcp from netlib import tcp
from netlib.http import status_codes, http1 from netlib.http import status_codes, http1, HttpErrorConnClosed
from netlib.http.semantics import CONTENT_MISSING from netlib.http.semantics import CONTENT_MISSING
from netlib import odict from netlib import odict
from netlib.tcp import NetLibError
def make_error_response(status_code, message, headers=None): def make_error_response(status_code, message, headers=None):
@ -66,7 +67,6 @@ def make_connect_response(httpversion):
class HttpLayer(Layer): class HttpLayer(Layer):
""" """
HTTP 1 Layer HTTP 1 Layer
""" """
@ -77,6 +77,7 @@ class HttpLayer(Layer):
def __call__(self): def __call__(self):
while True: while True:
try:
try: try:
request = HTTP1.read_request( request = HTTP1.read_request(
self.client_conn, self.client_conn,
@ -123,6 +124,9 @@ class HttpLayer(Layer):
if flow.request.form_in == "authority" and flow.response.code == 200: if flow.request.form_in == "authority" and flow.response.code == 200:
raise NotImplementedError("Upstream mode CONNECT not implemented") raise NotImplementedError("Upstream mode CONNECT not implemented")
except (HttpErrorConnClosed, NetLibError) as e:
make_error_response(502, repr(e))
raise ProtocolException(repr(e), e)
def check_close_connection(self, flow): def check_close_connection(self, flow):
""" """
@ -189,7 +193,7 @@ class HttpLayer(Layer):
flow.response.timestamp_end = utils.timestamp() flow.response.timestamp_end = utils.timestamp()
def get_response_from_server(self, flow): def get_response_from_server(self, flow):
# TODO: Add second attempt.
self.send_to_server(flow.request) self.send_to_server(flow.request)
flow.response = HTTP1.read_response( flow.response = HTTP1.read_response(
@ -327,7 +331,6 @@ class HttpLayer(Layer):
def send_to_server(self, message): def send_to_server(self, message):
self.server_conn.send(HTTP1.assemble(message)) self.server_conn.send(HTTP1.assemble(message))
def send_to_client(self, message): def send_to_client(self, message):
# FIXME # FIXME
# - possibly do some http2 stuff here # - possibly do some http2 stuff here

View File

@ -1,6 +1,7 @@
from __future__ import (absolute_import, print_function, division) from __future__ import (absolute_import, print_function, division)
from .layer import Layer, ServerConnectionMixin from .layer import Layer, ServerConnectionMixin
from .http import HttpLayer
class HttpProxy(Layer, ServerConnectionMixin): class HttpProxy(Layer, ServerConnectionMixin):
@ -21,5 +22,3 @@ class HttpUpstreamProxy(Layer, ServerConnectionMixin):
for message in layer(): for message in layer():
if not self._handle_server_message(message): if not self._handle_server_message(message):
yield message yield message
from .http import HttpLayer

View File

@ -200,7 +200,6 @@ def yield_from_callback(fun):
if msg is True: if msg is True:
break break
elif isinstance(msg, Exception): elif isinstance(msg, Exception):
# TODO: Include func name?
raise ProtocolException("Error in %s: %s" % (fun.__name__, repr(msg)), msg) raise ProtocolException("Error in %s: %s" % (fun.__name__, repr(msg)), msg)
else: else:
yield msg yield msg