Commit Graph

675 Commits

Author SHA1 Message Date
Aldo Cortesi
b2f63458fc Move human-friendly format functions to netlib.human, remove redundant implementations 2016-05-31 19:32:08 +12:00
Aldo Cortesi
ec34cae618 utils.multipartdecode -> http.multipart.decode
also

utils.parse_content_type -> http.headers.parse_content_type
2016-05-31 19:07:55 +12:00
Aldo Cortesi
15b2374ef9 netlib.utils.get_header_tokens -> netlib.http1.read.get_header_tokens
Placing this next to its only use.
2016-05-31 18:54:42 +12:00
Aldo Cortesi
da074bff01 isascii is unused 2016-05-31 18:51:40 +12:00
Aldo Cortesi
6dda2b2ee5 Module is part of the name - url.decode, not url.urldecode
A pattern we need to use far more often in the codebase
2016-05-31 18:46:19 +12:00
Aldo Cortesi
4e6c9c4e93 Extract url functions from netlib.utils and move to netlib.http.url 2016-05-31 18:42:56 +12:00
Aldo Cortesi
08fbe6f111 Start cleaning up netlib.utils
- Remove http2 functions, move to http2.frame
- Remove Serializable, move to netlib.basetypes
2016-05-31 17:16:31 +12:00
Aldo Cortesi
9ea68ebd28 Improve handling of pseudo-headers
- The canonical source for :method, :scheme and :path are the .method, .scheme
and .path attributes on the request object.
- These pseudo-headers are stripped after reading the request, and re-inserted
just before sending.
- The :authority header remains, and should be handled analagously to the Host
header in HTTP1 with respect to display and user interaction.
2016-05-31 14:36:17 +12:00
Aldo Cortesi
e8290a0eb4 Satisfy flake8 2016-05-30 12:41:44 +12:00
Thomas Kriechbaumer
e723c2d6ad fix bytes vs. str 2016-05-29 22:17:45 +02:00
Thomas Kriechbaumer
03167d5e71 fix headers order 2016-05-29 22:07:22 +02:00
Thomas Kriechbaumer
d76e5ad1ee raise a more verbose error 2016-05-29 19:28:59 +02:00
Thomas Kriechbaumer
e2447406cc more style cleanup 2016-05-29 13:43:20 +02:00
Thomas Kriechbaumer
8eeab37a07 more style cleanup
Use this to check:
flake8 --count mitmproxy netlib pathod examples test
2016-05-29 11:55:12 +02:00
Aldo Cortesi
f3bee6f245 Merge pull request #1172 from cortesi/solidcore
First steps to solidifying the core
2016-05-29 20:03:40 +12:00
Maximilian Hils
85aa5da6e3 fix tests 2016-05-28 19:31:43 -07:00
Maximilian Hils
b70663f434 minor improvements 2016-05-28 19:10:49 -07:00
Aldo Cortesi
ed415877d4 Merge branch 'master' into solidcore 2016-05-29 11:14:46 +12:00
Thomas Kriechbaumer
e5038c9ab7 netlib: fix most flake8 offenses 2016-05-28 22:17:02 +02:00
Thomas Kriechbaumer
caee1adeb6 cleanup imports with flake8 2016-05-28 14:43:32 +02:00
Aldo Cortesi
735bbe52e1 Merge branch 'master' into solidcore 2016-05-28 13:09:35 +12:00
Aldo Cortesi
3a9e03ea1e Fix crash in mitmproxy when viewing responses 2016-05-28 13:04:34 +12:00
Aldo Cortesi
7c4843857b Sketch out a more solid core
- Decorator for handler methods
- Stricter checking for double-acks and non-acks
2016-05-28 11:00:00 +12:00
Maximilian Hils
d149c447fe fix py3 tests 2016-05-25 20:31:32 -07:00
Maximilian Hils
d3477e27fa bytes_to_escaped_str: always escape single quotes 2016-05-25 20:11:34 -07:00
Maximilian Hils
7a8da48a30 escaped_str_to_bytes: support unicode on python 2 2016-05-25 19:16:02 -07:00
Maximilian Hils
dcad3f72af Merge branch 'issue-1099' 2016-05-20 20:02:56 -07:00
Aldo Cortesi
a5c4cd0340 A clearer implementation of MultiDictView
This makes MultiDictView work with a simple getter/setter pair, rather than
using attributes with implicit leading underscores. Also move MultiDictView
into multidict.py and adds some simple unit tests.
2016-05-21 11:37:36 +12:00
Aldo Cortesi
96d8ec1ee3 Merge branch 'multidict' of https://github.com/mhils/mitmproxy into mhils-multidict 2016-05-21 10:15:37 +12:00
Maximilian Hils
eb914924ab fix #1099 2016-05-20 13:59:42 -07:00
Maximilian Hils
b538138ead tests++ 2016-05-20 11:04:27 -07:00
Maximilian Hils
560fc756aa fix Header docs 2016-05-20 09:37:13 -07:00
Maximilian Hils
6f8db2d7eb improve MultiDict, add ImmutableMultiDict, adjust response.cookies 2016-05-18 22:50:19 -07:00
Maximilian Hils
d1fc694952 clean up odict 2016-05-18 19:01:49 -07:00
Maximilian Hils
44ac64aa72 add MultiDict
This commit introduces MultiDict, a multi-dictionary similar to
ODict, but with improved semantics (as in the Headers class).
MultiDict fixes a few issues that were present in the Request/Response
API. In particular, `request.cookies["foo"] = "bar"` has previously been a
no-op, as the cookies property returned a mutable _copy_ of the cookies.
2016-05-18 18:46:42 -07:00
Maximilian Hils
f1c922c652 Sanitize Print (#1135)
* sanitize strings with shell control characters

* netlib: add utilities to safe-print bytes

* escaped str: add TODO for multi-byte chars
2016-05-12 11:03:57 -06:00
Thomas Kriechbaumer
e2ee48a0ee replace SimpleCookie with our own parser lib 2016-05-11 12:20:21 -05:00
Thomas Kriechbaumer
08002282e8 improve cookie parsing
allows '/' to be within a cookie name
removes deprecated cookie getter/setter
fixes #1118
2016-05-10 11:13:12 -05:00
Maximilian Hils
9d47d3b1ec fix #1120 2016-05-09 12:15:20 -06:00
Maximilian Hils
54c4859a95 remove netlib version check 2016-04-29 12:00:38 -07:00
Maximilian Hils
49d1bcc8a2 fix CONNECT display in upstream mode 2016-04-20 15:27:39 -07:00
Maximilian Hils
70e35b7017 peer_address -> ip_address 2016-04-11 14:14:18 -07:00
Maximilian Hils
c22b14fae7 bump version 2016-04-09 20:01:24 -07:00
Maximilian Hils
0259f47997 Merge branch 'better-replace' 2016-04-03 08:17:30 -07:00
Thomas Kriechbaumer
f5fe93bf13 Merge pull request #1074 from mitmproxy/move-response-refresh
move HTTPResponse.refresh into netlib
2016-04-03 10:16:39 +02:00
Thomas Kriechbaumer
16fdbb4f2f Merge pull request #1073 from mitmproxy/first-line-format
form_(in|out) -> first_line_format
2016-04-03 10:16:06 +02:00
Maximilian Hils
35a6d6e7f6 response.msg -> response.reason 2016-04-02 22:54:46 +02:00
Maximilian Hils
4e2acc4d9d move HTTPResponse.refresh into netlib 2016-04-02 22:49:05 +02:00
Maximilian Hils
e6fa2688c9 form_(in|out) -> first_line_format 2016-04-02 21:57:35 +02:00
Maximilian Hils
4bdf7e035e fix #1067 2016-04-02 20:20:28 +02:00
Maximilian Hils
806aa0f41c improve .replace() and move it into netlib 2016-04-02 14:38:33 +02:00
Maximilian Hils
4ee8808b44 add Serializeable.copy 2016-04-02 13:50:53 +02:00
Thomas Kriechbaumer
ec68d8b8e4 s/nocover/no cover/g
according to coveralls docs
2016-03-27 12:02:41 +02:00
Matthew Shao
66bd27e6f9 update comments 2016-03-26 17:49:22 +08:00
Matthew Shao
08ff00f36d replace CONTENT_MISSING with None. 2016-03-26 16:00:51 +08:00
Matthew Shao
2f285a6015 Setting CONTENT_MISSING to None 2016-03-26 11:26:42 +08:00
Maximilian Hils
403ac82a7d netlib: request.path can be None 2016-03-20 23:22:50 +01:00
Maximilian Hils
983b0dd4f6 Merge pull request #1014 from ikoz/master
New option: Add server certs to client chain
2016-03-17 02:28:00 +01:00
Maximilian Hils
2a20fc59b2 Merge pull request #1030 from xhy940801/socks
Add 'UsernamePasswordAuth' 'UsernamePasswordAuthResponse' to SOCKS
2016-03-16 12:16:52 +01:00
lilydjwg
eecadadce3 use "peer_address" instead of "sock_address" 2016-03-15 21:32:06 +08:00
yonder
ba933dff2c Add 'UsernamePasswordAuth' 'UsernamePasswordAuthResponse' to SOCKS 2016-03-15 14:33:20 +08:00
依云
e9bff5ac56 add resolved IP address in "Details" tab 2016-03-10 21:23:31 +08:00
ikoz
0169271bf9 New option: Add server certs to client chain
If enabled, append all server certificates to the certificate chain
served to the client, as extras. Can be used to bypass certain
certificate pinning impementations.
2016-03-08 18:13:36 +00:00
Maximilian Hils
2bec6a35e2 fix #956 2016-02-19 00:30:37 +01:00
Maximilian Hils
ecb26c3c82 Merge remote-tracking branch 'duffer/pretty-host' 2016-02-18 23:17:02 +01:00
Shadab Zafar
9dc1224282 Incorporate comments made during review 2016-02-18 20:12:45 +05:30
Maximilian Hils
20352f3453 fix test paths, move coverage config into setup.py 2016-02-18 13:24:17 +01:00
Maximilian Hils
d33d3663ec combine projects 2016-02-18 13:03:40 +01:00
Shadab Zafar
175109e44e Use host header values only when the ports match 2016-02-18 07:01:52 +05:30
Shadab Zafar
6f96da08c9 Handle port numbers in host header
from: https://github.com/mitmproxy/netlib/pull/121
2016-02-17 08:48:59 +05:30
Thomas Kriechbaumer
6b585023fd move tservers helper 2016-02-16 21:53:16 +01:00
Maximilian Hils
5101843683 fix wheel creation, re-add MANIFEST.in 2016-02-16 04:28:10 +01:00
Will Coster
a69d223b33 Preserve host header when modifying request path
Currently the path_components and query setters of the Request object
use the url setter under the hood. The url setter updates all parts of
the URL including the host. If the host header and the host in the
request URL are different (as is common when making HTTPS requests)
then the host header will be updated to the value in the URL as a
result of modifying the path.

This change fixes this problem by modifying the query and
path_components setters to not use the url setter and instead directly
update the path field.
2016-02-15 16:21:20 -08:00
Maximilian Hils
4583fa7922 remove MANIFEST.in, move Dockerfile to root 2016-02-16 00:57:42 +01:00
Maximilian Hils
10f9b6faa7 fix release tool, refs #947 2016-02-16 00:22:38 +01:00
Maximilian Hils
3d9a5157e7 use own shields instance, update pathod readme 2016-02-15 21:13:06 +01:00
Maximilian Hils
a1190c3696 adjust travis 2016-02-15 17:06:32 +01:00
Maximilian Hils
b211bef9a1 fix tests 2016-02-15 16:34:38 +01:00
Maximilian Hils
d7158f975e move tests into shared folder 2016-02-15 16:34:22 +01:00
Maximilian Hils
95cef3c0e9 merge metadata files 2016-02-15 15:43:59 +01:00
Maximilian Hils
43c3e164ec add netlib 2016-02-15 14:58:48 +01:00
Maximilian Hils
aafa69a738 bump version 2016-02-14 17:25:30 +01:00
Maximilian Hils
1dcb8b14ac bump version 2016-02-08 15:09:29 +01:00
Maximilian Hils
ead9b0ab8c fix http version string 2016-02-08 15:09:25 +01:00
Maximilian Hils
655b521749 fix docstrings 2016-02-08 04:33:10 +01:00
Maximilian Hils
173ff0b235 fix py3 compat 2016-02-08 04:28:49 +01:00
Maximilian Hils
fe0ed63c4a add Serializable ABC 2016-02-08 04:16:58 +01:00
Maximilian Hils
4873547de3 minor fixes 2016-02-08 02:10:48 +01:00
Maximilian Hils
8f8796f9d9 expose OpenSSL's HAS_ALPN 2016-02-08 00:40:55 +01:00
Maximilian Hils
0336a53aa8 Merge branch 'master' of https://github.com/mitmproxy/netlib 2016-02-02 18:16:05 +01:00
Maximilian Hils
a188ae5ac5 allow creation of certs without CN 2016-02-02 18:15:55 +01:00
Thomas Kriechbaumer
e222858f01 bump dependency and remove deprecated fields 2016-02-02 17:39:49 +01:00
Thomas Kriechbaumer
81b32cf426 Merge pull request #116 from Kriechi/hyperframe
migrate to hyperframe
2016-02-01 20:28:14 +01:00
Maximilian Hils
931b5459e9 remove code duplication 2016-02-01 20:19:34 +01:00
Maximilian Hils
a3af0ce71d tests++ 2016-02-01 20:10:18 +01:00
Maximilian Hils
bda49dd178 fix #113, make Reader.peek() work on Python 3 2016-02-01 19:38:14 +01:00
Thomas Kriechbaumer
e98c729bb9 test on python3 2016-01-31 20:19:32 +01:00
Thomas Kriechbaumer
280b491ab2 migrate to hyperframe 2016-01-31 20:03:25 +01:00
Thomas Kriechbaumer
d253ebc142 fix test request and response headers 2016-01-30 22:03:24 +01:00
Thomas Kriechbaumer
1b487539b1 move tservers to netlib module 2016-01-25 09:20:44 +01:00
Sandor Nemes
b8e8c4d682 Simplified setting the source_address in the TCPClient constructor 2016-01-11 08:10:36 +01:00
Sandor Nemes
4bb9f3d35b Added getter/setter for TCPClient source_address 2016-01-08 18:04:47 +01:00
Maximilian Hils
d1e6b5366c bump version 2015-12-25 16:00:50 +01:00
Maximilian Hils
71834421bb bump version 2015-12-03 18:13:24 +01:00
Benjamin Lee
c1385c9a17 Fix to ignore empty header value.
According to Augmented BNF in the following RFCs

http://tools.ietf.org/html/rfc5234#section-3.6

http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.1

        field-value    = *( field-content | LWS )

http://tools.ietf.org/html/rfc7230#section-3.2

        field-value    = *( field-content / obs-fold )

... the HTTP message header `field-value` is allowed to be empty.
2015-11-17 04:51:20 +11:00
Sam Cleveland
2bd7bcb371 Porting to Python 3.4
Updated wsgi to support Python 3.4 byte strings.
Updated test_wsgi to remove py.test warning for TestApp having an
__init__ constructor.

samc$ sudo py.test netlib/test/test_wsgi.py -r w
= test session starts =
platform darwin -- Python 3.4.1, pytest-2.8.2, py-1.4.30, pluggy-0.3.1
rootdir: /Users/samc/src/python/netlib, inifile:
collected 6 items

netlib/test/test_wsgi.py ......

= 6 passed in 0.20 seconds =
2015-11-11 20:27:10 -06:00
Sam Cleveland
6689a342ae Porting to Python 3.4
Fixed byte string formatting for hexdump.

= test session starts =
platform darwin -- Python 3.4.1, pytest-2.8.2, py-1.4.30, pluggy-0.3.1
rootdir: /Users/samc/src/python/netlib, inifile:
collected 11 items

netlib/test/test_utils.py ...........

= 11 passed in 0.23 seconds =
2015-11-11 19:53:51 -06:00
Sam Cleveland
2d48f12332 Revert "Porting netlib to python3.4"
This reverts commit 8237183485.
2015-11-11 19:41:42 -06:00
Sam Cleveland
8237183485 Porting netlib to python3.4
Updated utils.py using 2to3-3.4
Updated hexdump to use .format() with .encode() to support python 3.4
Python 3.5 supports .format() on bytes objects, but 3.4 is the current
default on Ubuntu.

samc$ py.test netlib/test/test_utils.py
= test session starts =
platform darwin -- Python 3.4.1, pytest-2.8.2, py-1.4.30, pluggy-0.3.1
rootdir: /Users/samc/src/python/netlib, inifile:
collected 11 items

netlib/test/test_utils.py ...........

= 11 passed in 0.19 seconds =
2015-11-11 11:32:02 -06:00
Aldo Cortesi
9cab9ee5d6 Bump version for next release cycle 2015-11-07 09:30:49 +13:00
Aldo Cortesi
3e2eb3fef1 Bump version 2015-11-06 13:51:15 +13:00
Maximilian Hils
810c2f2414 Merge remote-tracking branch 'origin/hostname-validation' 2015-11-04 21:33:32 +01:00
Maximilian Hils
9d12425d5e Set default cert expiry to <39 months
This sould fix mitmproxy/mitmproxy#815
2015-11-04 11:28:02 +01:00
Maximilian Hils
9d36f8e43f minor fixes 2015-11-01 18:20:00 +01:00
Maximilian Hils
5af9df326a fix certificate verification
This commit fixes netlib's optional (turned off by default)
certificate verification, which previously did not validate the
cert's host name. As it turns out, verifying the connection's host
name on an intercepting proxy is not really straightforward - if
we receive a connection in transparent mode without SNI, we have no
clue which hosts the client intends to connect to. There are two
basic approaches to solve this problem:

 1. Exactly mirror the host names presented by the server in the
    spoofed certificate presented to the client.
 2. Require the client to send the TLS Server Name Indication
    extension. While this does not work with older clients,
    we can validate the hostname on the proxy.

Approach 1 is problematic in mitmproxy's use case, as we may want
to deliberately divert connections without the client's knowledge.
As a consequence, we opt for approach 2. While mitmproxy does now
require a SNI value to be sent by the client if certificate
verification is turned on, we retain our ability to present
certificates to the client which are accepted with a maximum
likelihood.
2015-11-01 18:15:30 +01:00
Maximilian Hils
67229fbdf7 Merge branch 'http-models' 2015-09-28 13:53:59 +02:00
Maximilian Hils
87566da3ba fix mitmproxy/mitmproxy#784 2015-09-28 11:18:00 +02:00
Maximilian Hils
23d13e4c12 test response model, push coverage to 100% branch cov 2015-09-27 00:49:41 +02:00
Maximilian Hils
466888b01a improve request tests, coverage++ 2015-09-26 20:07:11 +02:00
Maximilian Hils
49ea8fc0eb refactor response model 2015-09-26 17:39:50 +02:00
Maximilian Hils
106f7046d3 refactor request model 2015-09-26 00:39:04 +02:00
Maximilian Hils
45f2ea33b2 minor fixes 2015-09-25 18:24:18 +02:00
Maximilian Hils
c7b8322500 also accept bytes as arguments 2015-09-22 01:56:09 +02:00
Maximilian Hils
f937522773 Headers: return str on all Python versions 2015-09-22 01:48:35 +02:00
Maximilian Hils
9fbeac50ce revert websocket changes from 73586b1b
The DEFAULT construct is very weird,
but with None we apparently break pathod
in some difficult-to-debug ways.
Revisit once we do more here.
2015-09-21 22:49:39 +02:00
Thomas Kriechbaumer
e9fe45f3f4 backport changes 2015-09-21 18:45:49 +02:00
Maximilian Hils
1ff8f294b4 minor encoding fixes 2015-09-21 18:34:43 +02:00
Maximilian Hils
73586b1be9 python 3++ 2015-09-21 00:44:17 +02:00
Maximilian Hils
daebd1bd27 python3++ 2015-09-20 20:35:45 +02:00
Maximilian Hils
0ad5cbc6bf python3++ 2015-09-20 19:56:45 +02:00
Maximilian Hils
693cdfc6d7 python3++ 2015-09-20 19:40:09 +02:00
Maximilian Hils
3f1ca556d1 python3++ 2015-09-20 18:12:55 +02:00
Maximilian Hils
91cdd78201 improve http error messages 2015-09-19 11:59:40 +02:00
Maximilian Hils
551d9f11e5 experimental: don't interfere with headers 2015-09-18 18:05:50 +02:00
Maximilian Hils
d1904c2f52 python3++ 2015-09-18 15:38:31 +02:00
Maximilian Hils
7b6b157547 properly handle SNI IPs
fixes mitmproxy/mitmproxy#772
We must use the ipaddress package here, because that's what cryptography
uses. If we opt for something else, we have nasty namespace conflicts.
2015-09-18 15:35:02 +02:00
Maximilian Hils
266b80238d fix tests 2015-09-17 17:29:55 +02:00
Maximilian Hils
d798ed955d python3++ 2015-09-17 16:31:50 +02:00
Maximilian Hils
8d71059d77 clean up http message models 2015-09-17 15:16:12 +02:00
Maximilian Hils
a07e43df8b http1: add assemble_body function 2015-09-17 02:39:42 +02:00
Maximilian Hils
dad9f06cb9 organize exceptions, improve content-length handling 2015-09-17 02:14:14 +02:00
Maximilian Hils
265f31e878 adjust http1-related code 2015-09-16 18:43:24 +02:00
Maximilian Hils
a077d8877d finish netlib.http.http1 refactor 2015-09-16 00:04:23 +02:00
Maximilian Hils
11e7f476bd wip 2015-09-15 19:12:15 +02:00
Maximilian Hils
997fcde8ce make clean_bin unicode-aware 2015-09-12 17:03:09 +02:00
Maximilian Hils
a38142d595 don't yield empty chunks 2015-09-11 01:17:39 +02:00
Maximilian Hils
92c763f469 fix mitmproxy/mitmproxy#759 2015-09-10 12:32:38 +02:00
Maximilian Hils
a5f7752cf1 add ssl_read_select 2015-09-10 11:30:41 +02:00
Maximilian Hils
32b3c32138 add tcp.Address.__hash__ 2015-09-08 21:31:27 +02:00
Maximilian Hils
fc86bbd03e let Headers inherit from object
fixes mitmproxy/mitmproxy#753
2015-09-08 15:16:25 +02:00