Skip to content

Commit

Permalink
Cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
vfaronov committed Mar 12, 2017
1 parent 9b1053d commit 95aeea0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Added
- A new ``--tail`` option to regenerate the report on every new exchange,
so you can inspect traffic as it comes (see `docs`_).

- HTTPolice now writes brief summaries to mitmproxy’s eventlog, like this::
- HTTPolice now writes brief summaries to mitmproxy’s event log, like this::

HTTPolice found 1 errors, 2 comments in: GET /api/v1/ - 200 OK

(The eventlog is printed to the console when you use ``mitmdump``,
(The event log is printed to the console when you use ``mitmdump``,
or to the “Event log” pane when you press the ‘e’ key in ``mitmproxy``.)

- In the ``mitmproxy`` console UI, you can now see a brief report
Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ on its “Detail” tab:
__ http://docs.mitmproxy.org/en/stable/mitmproxy.html

How do you even know that there’s anything to see there?
Currently the only way is to follow the eventlog,
Currently the only way is to follow the event log,
which you can trigger by pressing the ‘e’ key:

.. image:: mitmproxy-eventlog.png
Expand Down
24 changes: 13 additions & 11 deletions mitmproxy_httpolice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import io
import os

import mitmproxy.ctx
import httpolice
import mitmproxy.ctx


__version__ = '0.6.0.dev1'
Expand All @@ -30,7 +30,7 @@ def start(argv=None):
args.silence)


class MitmproxyHTTPolice(object):
class MitmproxyHTTPolice:

def __init__(self, report_file, tail, output_format, silence):
self.report_file = report_file
Expand Down Expand Up @@ -75,14 +75,14 @@ def construct_request(flow):
# are simply rejected as errors by mitmproxy, closing the connection.
target = decode(flow.request.path)

if version == u'HTTP/2':
if version == 'HTTP/2':
pseudo_headers = httpolice.helpers.pop_pseudo_headers(headers)
authority = pseudo_headers.get(u':authority')
has_host = any(k.lower() == u'host' for (k, v) in headers)
if authority and not has_host and target.startswith(u'/'):
authority = pseudo_headers.get(':authority')
has_host = any(k.lower() == 'host' for (k, v) in headers)
if authority and not has_host and target.startswith('/'):
# Reconstruct HTTP/2's equivalent of
# the "absolute form" of request target (RFC 7540 Section 8.1.2.3).
target = scheme + u'://' + decode(authority) + target
target = scheme + '://' + decode(authority) + target

return httpolice.Request(scheme, method, target, version, headers, body)

Expand All @@ -91,15 +91,15 @@ def construct_response(flow):
version, headers, body = extract_message_basics(flow.response)
status = flow.response.status_code
reason = decode(flow.response.reason)
if version == u'HTTP/2':
if version == 'HTTP/2':
httpolice.helpers.pop_pseudo_headers(headers)
return httpolice.Response(version, status, reason, headers, body)


def extract_message_basics(msg):
version = decode(msg.http_version)
if version == u'HTTP/2.0':
version = u'HTTP/2'
if version == 'HTTP/2.0':
version = 'HTTP/2'
headers = [(decode(k), v) for (k, v) in msg.headers.fields]
body = msg.raw_content
return version, headers, body
Expand Down Expand Up @@ -149,7 +149,7 @@ def decode(s):

def ellipsize(s, max_length=40):
if len(s) > max_length:
ellipsis = u'...'
ellipsis = '...'
return s[:(max_length - len(ellipsis))] + ellipsis
else:
return s
Expand All @@ -160,6 +160,8 @@ class ReprString(str):
# Currently mitmproxy displays ``repr()`` in details view, not ``str()``.
# See also https://discourse.mitmproxy.org/t/extending-the-ui/359/5

__slots__ = []

def __repr__(self):
return str(self)

Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mitmproxy >= 2.0.0
HTTPolice >= 0.5.0.dev1
HTTPolice >= 0.5.0
2 changes: 1 addition & 1 deletion test_fake_mitmdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_complex(bench): # pylint: disable=redefined-outer-name
),
tutils.tresp(
http_version='HTTP/1.1',
status_code=201, reason=u'Très bien'.encode('iso-8859-1'),
status_code=201, reason='Très bien'.encode('iso-8859-1'),
headers=Headers([(b'Content-Type', b'text/plain'),
(b'Content-Length', b'14'),
(b'Date', b'Tue, 03 May 2016 14:13:34 GMT')]),
Expand Down
8 changes: 4 additions & 4 deletions test_real_mitmdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import pytest


class RealMitmdump(object):
class RealMitmdump:

# pylint: disable=attribute-defined-outside-init

Expand Down Expand Up @@ -55,9 +55,9 @@ def send_tunneled_request(self, host, port, data):
# We need our own TLS context that does not verify certificates.
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
sock = socket.create_connection((self.host, self.port))
connect = (u'CONNECT {0}:{1} HTTP/1.1\r\n'
u'Host: {0}\r\n'
u'\r\n'.format(host, port))
connect = ('CONNECT {0}:{1} HTTP/1.1\r\n'
'Host: {0}\r\n'
'\r\n'.format(host, port))
sock.sendall(connect.encode('iso-8859-1'))
assert sock.recv(4096).startswith(b'HTTP/1.1 2')
sock = context.wrap_socket(sock, server_hostname=host)
Expand Down

0 comments on commit 95aeea0

Please sign in to comment.