diff --git a/.appveyor.yml b/.appveyor.yml index 3886862894..746e0fd14d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -23,7 +23,7 @@ install: - "pip install -U tox" test_script: - - ps: "tox -- --cov netlib --cov mitmproxy --cov pathod -v" + - ps: "tox -- --cov mitmproxy --cov pathod -v" deploy_script: ps: | diff --git a/.travis.yml b/.travis.yml index d160a96eed..d7cb7027d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,7 @@ install: fi - pip install tox -script: tox -- --cov netlib --cov mitmproxy --cov pathod -v +script: tox -- --cov mitmproxy --cov pathod -v after_success: - | diff --git a/MANIFEST.in b/MANIFEST.in index 440a14ed73..404936e84e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,3 @@ graft mitmproxy graft pathod -graft netlib -recursive-exclude * *.pyc *.pyo *.swo *.swp *.map \ No newline at end of file +recursive-exclude * *.pyc *.pyo *.swo *.swp *.map diff --git a/README.rst b/README.rst index 146a2c439c..cdeada2d8f 100644 --- a/README.rst +++ b/README.rst @@ -3,8 +3,7 @@ mitmproxy |travis| |appveyor| |coverage| |latest_release| |python_versions| -This repository contains the **mitmproxy** and **pathod** projects, as well as -their shared networking library, **netlib**. +This repository contains the **mitmproxy** and **pathod** projects. ``mitmproxy`` is an interactive, SSL-capable intercepting proxy with a console interface. @@ -64,7 +63,7 @@ virtualenv_ installed (you can find installation instructions for virtualenv The *dev* script will create a virtualenv environment in a directory called "venv", and install all mandatory and optional dependencies into it. The -primary mitmproxy components - mitmproxy, netlib and pathod - are installed as +primary mitmproxy components - mitmproxy and pathod - are installed as "editable", so any changes to the source in the repository will be reflected live in the virtualenv. @@ -144,7 +143,7 @@ PR checks will fail and block merging. We are using this command to check for st .. code-block:: text - flake8 --jobs 8 --count mitmproxy netlib pathod examples test + flake8 --jobs 8 --count mitmproxy pathod examples test .. |mitmproxy_site| image:: https://shields.mitmproxy.org/api/https%3A%2F%2F-mitmproxy.org-blue.svg diff --git a/docs/conf.py b/docs/conf.py index ce942aa946..d7793b79c3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -231,10 +231,7 @@ def linkcode_resolve(domain, info): _, line = inspect.getsourcelines(obj) except (TypeError, IOError): return None - if spath.rfind("netlib") > -1: - off = spath.rfind("netlib") - mpath = spath[off:] - elif spath.rfind("mitmproxy") > -1: + if spath.rfind("mitmproxy") > -1: off = spath.rfind("mitmproxy") mpath = spath[off:] else: diff --git a/docs/dev/testing.rst b/docs/dev/testing.rst index 315b9bc90f..b86efce16f 100644 --- a/docs/dev/testing.rst +++ b/docs/dev/testing.rst @@ -10,7 +10,7 @@ suitable extension to the test suite. Our tests are written for the `py.test`_ or nose_ test frameworks. At the point where you send your pull request, a command like this: ->>> py.test --cov mitmproxy --cov netlib +>>> py.test --cov mitmproxy Should give output something like this: diff --git a/docs/modd.conf b/docs/modd.conf index bc91238c08..0e8f0dced1 100644 --- a/docs/modd.conf +++ b/docs/modd.conf @@ -1,6 +1,6 @@ @build = ./_build -** !_build/** ../netlib/**/*.py ../mitmproxy/**/*.py { +** !_build/** ../mitmproxy/**/*.py { prep: sphinx-build -W -d @build/doctrees -b html . @build/html daemon: devd -m @build/html } diff --git a/examples/har_dump.py b/examples/har_dump.py index d01e6cddcf..560b9adca1 100644 --- a/examples/har_dump.py +++ b/examples/har_dump.py @@ -16,7 +16,7 @@ from mitmproxy import version from mitmproxy.utils import strutils -from netlib.http import cookies +from mitmproxy.net.http import cookies HAR = {} diff --git a/mitmproxy/addons/stickycookie.py b/mitmproxy/addons/stickycookie.py index d89bd92d13..27d78646b1 100644 --- a/mitmproxy/addons/stickycookie.py +++ b/mitmproxy/addons/stickycookie.py @@ -1,7 +1,7 @@ import collections from http import cookiejar -from netlib.http import cookies +from mitmproxy.net.http import cookies from mitmproxy import exceptions from mitmproxy import flowfilter diff --git a/mitmproxy/addons/streambodies.py b/mitmproxy/addons/streambodies.py index bd8958b04c..88cb74f33c 100644 --- a/mitmproxy/addons/streambodies.py +++ b/mitmproxy/addons/streambodies.py @@ -1,4 +1,4 @@ -from netlib.http import http1 +from mitmproxy.net.http import http1 from mitmproxy import exceptions from mitmproxy import ctx diff --git a/mitmproxy/addons/wsgiapp.py b/mitmproxy/addons/wsgiapp.py index 0879a87be6..85d09a0aee 100644 --- a/mitmproxy/addons/wsgiapp.py +++ b/mitmproxy/addons/wsgiapp.py @@ -1,7 +1,7 @@ from mitmproxy import ctx from mitmproxy import exceptions -from netlib import wsgi +from mitmproxy.net import wsgi from mitmproxy import version diff --git a/mitmproxy/certs.py b/mitmproxy/certs.py index 9cb8a40ede..83db4e6e30 100644 --- a/mitmproxy/certs.py +++ b/mitmproxy/certs.py @@ -193,7 +193,7 @@ def expire(self, entry): @staticmethod def load_dhparam(path): - # netlib<=0.10 doesn't generate a dhparam file. + # mitmproxy<=0.10 doesn't generate a dhparam file. # Create it now if neccessary. if not os.path.exists(path): with open(path, "wb") as f: diff --git a/mitmproxy/connections.py b/mitmproxy/connections.py index 6b39ac2072..015d068947 100644 --- a/mitmproxy/connections.py +++ b/mitmproxy/connections.py @@ -5,7 +5,7 @@ from mitmproxy import stateobject from mitmproxy import certs -from netlib import tcp +from mitmproxy.net import tcp class ClientConnection(tcp.BaseHandler, stateobject.StateObject): diff --git a/mitmproxy/contentviews.py b/mitmproxy/contentviews.py index a171f36bf3..b7f15d8d78 100644 --- a/mitmproxy/contentviews.py +++ b/mitmproxy/contentviews.py @@ -33,10 +33,10 @@ from PIL import Image from mitmproxy import exceptions from mitmproxy.contrib.wbxml import ASCommandResponse -from netlib import http +from mitmproxy.net import http from mitmproxy.types import multidict from mitmproxy.utils import strutils -from netlib.http import url +from mitmproxy.net.http import url try: import pyamf diff --git a/mitmproxy/exceptions.py b/mitmproxy/exceptions.py index a7ecf17f1e..309b81892b 100644 --- a/mitmproxy/exceptions.py +++ b/mitmproxy/exceptions.py @@ -112,7 +112,7 @@ class AddonHalt(MitmproxyException): class NetlibException(MitmproxyException): """ - Base class for all exceptions thrown by netlib. + Base class for all exceptions thrown by mitmproxy.net. """ def __init__(self, message=None): super().__init__(message) diff --git a/mitmproxy/export.py b/mitmproxy/export.py index e5f4d34a54..d9a88849dd 100644 --- a/mitmproxy/export.py +++ b/mitmproxy/export.py @@ -3,7 +3,7 @@ import textwrap import urllib -import netlib.http +import mitmproxy.net.http def _native(s): @@ -89,9 +89,9 @@ def python_code(flow): return code -def is_json(headers: netlib.http.Headers, content: bytes) -> bool: +def is_json(headers: mitmproxy.net.http.Headers, content: bytes) -> bool: if headers: - ct = netlib.http.parse_content_type(headers.get("content-type", "")) + ct = mitmproxy.net.http.parse_content_type(headers.get("content-type", "")) if ct and "%s/%s" % (ct[0], ct[1]) == "application/json": try: return json.loads(content.decode("utf8", "surrogateescape")) diff --git a/mitmproxy/http.py b/mitmproxy/http.py index 4474ca3be6..99e126feb8 100644 --- a/mitmproxy/http.py +++ b/mitmproxy/http.py @@ -1,9 +1,9 @@ import cgi from mitmproxy import flow -from netlib import http +from mitmproxy.net import http from mitmproxy import version -from netlib import tcp +from mitmproxy.net import tcp class HTTPRequest(http.Request): @@ -12,7 +12,7 @@ class HTTPRequest(http.Request): A mitmproxy HTTP request. """ - # This is a very thin wrapper on top of :py:class:`netlib.http.Request` and + # This is a very thin wrapper on top of :py:class:`mitmproxy.net.http.Request` and # may be removed in the future. def __init__( @@ -73,7 +73,7 @@ def set_state(self, state): @classmethod def wrap(self, request): """ - Wraps an existing :py:class:`netlib.http.Request`. + Wraps an existing :py:class:`mitmproxy.net.http.Request`. """ req = HTTPRequest( first_line_format=request.data.first_line_format, @@ -99,7 +99,7 @@ class HTTPResponse(http.Response): """ A mitmproxy HTTP response. """ - # This is a very thin wrapper on top of :py:class:`netlib.http.Response` and + # This is a very thin wrapper on top of :py:class:`mitmproxy.net.http.Response` and # may be removed in the future. def __init__( @@ -131,7 +131,7 @@ def __init__( @classmethod def wrap(self, response): """ - Wraps an existing :py:class:`netlib.http.Response`. + Wraps an existing :py:class:`mitmproxy.net.http.Response`. """ resp = HTTPResponse( http_version=response.data.http_version, diff --git a/mitmproxy/master.py b/mitmproxy/master.py index 2e57e57d30..31ce17a3aa 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -15,7 +15,7 @@ from mitmproxy import io from mitmproxy.proxy.protocol import http_replay from mitmproxy.types import basethread -import netlib.http +import mitmproxy.net.http from . import ctx as mitmproxy_ctx @@ -122,7 +122,7 @@ def create_request(self, method, scheme, host, port, path): s = connections.ServerConnection.make_dummy((host, port)) f = http.HTTPFlow(c, s) - headers = netlib.http.Headers() + headers = mitmproxy.net.http.Headers() req = http.HTTPRequest( "absolute", diff --git a/netlib/__init__.py b/mitmproxy/net/__init__.py similarity index 100% rename from netlib/__init__.py rename to mitmproxy/net/__init__.py diff --git a/netlib/check.py b/mitmproxy/net/check.py similarity index 100% rename from netlib/check.py rename to mitmproxy/net/check.py diff --git a/mitmproxy/net/http/__init__.py b/mitmproxy/net/http/__init__.py new file mode 100644 index 0000000000..7e290bdc61 --- /dev/null +++ b/mitmproxy/net/http/__init__.py @@ -0,0 +1,15 @@ +from mitmproxy.net.http.request import Request +from mitmproxy.net.http.response import Response +from mitmproxy.net.http.message import Message +from mitmproxy.net.http.headers import Headers, parse_content_type +from mitmproxy.net.http.message import decoded +from mitmproxy.net.http import http1, http2, status_codes, multipart + +__all__ = [ + "Request", + "Response", + "Message", + "Headers", "parse_content_type", + "decoded", + "http1", "http2", "status_codes", "multipart", +] diff --git a/netlib/http/authentication.py b/mitmproxy/net/http/authentication.py similarity index 100% rename from netlib/http/authentication.py rename to mitmproxy/net/http/authentication.py diff --git a/netlib/http/cookies.py b/mitmproxy/net/http/cookies.py similarity index 100% rename from netlib/http/cookies.py rename to mitmproxy/net/http/cookies.py diff --git a/netlib/http/encoding.py b/mitmproxy/net/http/encoding.py similarity index 100% rename from netlib/http/encoding.py rename to mitmproxy/net/http/encoding.py diff --git a/netlib/http/headers.py b/mitmproxy/net/http/headers.py similarity index 100% rename from netlib/http/headers.py rename to mitmproxy/net/http/headers.py diff --git a/netlib/http/http1/__init__.py b/mitmproxy/net/http/http1/__init__.py similarity index 100% rename from netlib/http/http1/__init__.py rename to mitmproxy/net/http/http1/__init__.py diff --git a/netlib/http/http1/assemble.py b/mitmproxy/net/http/http1/assemble.py similarity index 92% rename from netlib/http/http1/assemble.py rename to mitmproxy/net/http/http1/assemble.py index e0a91ad803..d718589f44 100644 --- a/netlib/http/http1/assemble.py +++ b/mitmproxy/net/http/http1/assemble.py @@ -1,4 +1,4 @@ -import netlib.http.url +import mitmproxy.net.http.url from mitmproxy import exceptions @@ -44,7 +44,7 @@ def assemble_body(headers, body_chunks): def _assemble_request_line(request_data): """ Args: - request_data (netlib.http.request.RequestData) + request_data (mitmproxy.net.http.request.RequestData) """ form = request_data.first_line_format if form == "relative": @@ -76,11 +76,11 @@ def _assemble_request_line(request_data): def _assemble_request_headers(request_data): """ Args: - request_data (netlib.http.request.RequestData) + request_data (mitmproxy.net.http.request.RequestData) """ headers = request_data.headers.copy() if "host" not in headers and request_data.scheme and request_data.host and request_data.port: - headers["host"] = netlib.http.url.hostport( + headers["host"] = mitmproxy.net.http.url.hostport( request_data.scheme, request_data.host, request_data.port diff --git a/netlib/http/http1/read.py b/mitmproxy/net/http/http1/read.py similarity index 98% rename from netlib/http/http1/read.py rename to mitmproxy/net/http/http1/read.py index e6b22863e0..6eb30709b2 100644 --- a/netlib/http/http1/read.py +++ b/mitmproxy/net/http/http1/read.py @@ -2,11 +2,11 @@ import sys import re -from netlib.http import request -from netlib.http import response -from netlib.http import headers -from netlib.http import url -from netlib import check +from mitmproxy.net.http import request +from mitmproxy.net.http import response +from mitmproxy.net.http import headers +from mitmproxy.net.http import url +from mitmproxy.net import check from mitmproxy import exceptions diff --git a/mitmproxy/net/http/http2/__init__.py b/mitmproxy/net/http/http2/__init__.py new file mode 100644 index 0000000000..7027006be8 --- /dev/null +++ b/mitmproxy/net/http/http2/__init__.py @@ -0,0 +1,8 @@ +from mitmproxy.net.http.http2.framereader import read_raw_frame, parse_frame +from mitmproxy.net.http.http2.utils import parse_headers + +__all__ = [ + "read_raw_frame", + "parse_frame", + "parse_headers", +] diff --git a/netlib/http/http2/framereader.py b/mitmproxy/net/http/http2/framereader.py similarity index 100% rename from netlib/http/http2/framereader.py rename to mitmproxy/net/http/http2/framereader.py diff --git a/netlib/http/http2/utils.py b/mitmproxy/net/http/http2/utils.py similarity index 96% rename from netlib/http/http2/utils.py rename to mitmproxy/net/http/http2/utils.py index 164bacc8a6..62a59c7270 100644 --- a/netlib/http/http2/utils.py +++ b/mitmproxy/net/http/http2/utils.py @@ -1,4 +1,4 @@ -from netlib.http import url +from mitmproxy.net.http import url def parse_headers(headers): diff --git a/netlib/http/message.py b/mitmproxy/net/http/message.py similarity index 98% rename from netlib/http/message.py rename to mitmproxy/net/http/message.py index 772a124e6f..af1d16beaa 100644 --- a/netlib/http/message.py +++ b/mitmproxy/net/http/message.py @@ -3,9 +3,9 @@ from typing import Optional from mitmproxy.utils import strutils -from netlib.http import encoding +from mitmproxy.net.http import encoding from mitmproxy.types import serializable -from netlib.http import headers +from mitmproxy.net.http import headers # While headers _should_ be ASCII, it's not uncommon for certain headers to be utf-8 encoded. @@ -69,7 +69,7 @@ def headers(self): Message headers object Returns: - netlib.http.Headers + mitmproxy.net.http.Headers """ return self.data.headers diff --git a/netlib/http/multipart.py b/mitmproxy/net/http/multipart.py similarity index 95% rename from netlib/http/multipart.py rename to mitmproxy/net/http/multipart.py index 536b2809d2..a854d47fd4 100644 --- a/netlib/http/multipart.py +++ b/mitmproxy/net/http/multipart.py @@ -1,6 +1,6 @@ import re -from netlib.http import headers +from mitmproxy.net.http import headers def decode(hdrs, content): diff --git a/netlib/http/request.py b/mitmproxy/net/http/request.py similarity index 90% rename from netlib/http/request.py rename to mitmproxy/net/http/request.py index 16b0c986b0..c3d8536353 100644 --- a/netlib/http/request.py +++ b/mitmproxy/net/http/request.py @@ -3,11 +3,11 @@ from mitmproxy.types import multidict from mitmproxy.utils import strutils -from netlib.http import multipart -from netlib.http import cookies -from netlib.http import headers as nheaders -from netlib.http import message -import netlib.http.url +from mitmproxy.net.http import multipart +from mitmproxy.net.http import cookies +from mitmproxy.net.http import headers as nheaders +from mitmproxy.net.http import message +import mitmproxy.net.http.url # This regex extracts & splits the host header into host and port. # Handles the edge case of IPv6 addresses containing colons. @@ -203,11 +203,11 @@ def url(self): """ if self.first_line_format == "authority": return "%s:%d" % (self.host, self.port) - return netlib.http.url.unparse(self.scheme, self.host, self.port, self.path) + return mitmproxy.net.http.url.unparse(self.scheme, self.host, self.port, self.path) @url.setter def url(self, url): - self.scheme, self.host, self.port, self.path = netlib.http.url.parse(url) + self.scheme, self.host, self.port, self.path = mitmproxy.net.http.url.parse(url) def _parse_host_header(self): """Extract the host and port from Host header""" @@ -243,12 +243,12 @@ def pretty_url(self): """ if self.first_line_format == "authority": return "%s:%d" % (self.pretty_host, self.port) - return netlib.http.url.unparse(self.scheme, self.pretty_host, self.port, self.path) + return mitmproxy.net.http.url.unparse(self.scheme, self.pretty_host, self.port, self.path) @property def query(self) -> multidict.MultiDictView: """ - The request query string as an :py:class:`~netlib.multidict.MultiDictView` object. + The request query string as an :py:class:`~mitmproxy.net.multidict.MultiDictView` object. """ return multidict.MultiDictView( self._get_query, @@ -257,10 +257,10 @@ def query(self) -> multidict.MultiDictView: def _get_query(self): query = urllib.parse.urlparse(self.url).query - return tuple(netlib.http.url.decode(query)) + return tuple(mitmproxy.net.http.url.decode(query)) def _set_query(self, query_data): - query = netlib.http.url.encode(query_data) + query = mitmproxy.net.http.url.encode(query_data) _, _, path, params, _, fragment = urllib.parse.urlparse(self.url) self.path = urllib.parse.urlunparse(["", "", path, params, query, fragment]) @@ -273,7 +273,7 @@ def cookies(self) -> multidict.MultiDictView: """ The request cookies. - An empty :py:class:`~netlib.multidict.MultiDictView` object if the cookie monster ate them all. + An empty :py:class:`~mitmproxy.net.multidict.MultiDictView` object if the cookie monster ate them all. """ return multidict.MultiDictView( self._get_cookies, @@ -301,11 +301,11 @@ def path_components(self): # This needs to be a tuple so that it's immutable. # Otherwise, this would fail silently: # request.path_components.append("foo") - return tuple(netlib.http.url.unquote(i) for i in path.split("/") if i) + return tuple(mitmproxy.net.http.url.unquote(i) for i in path.split("/") if i) @path_components.setter def path_components(self, components): - components = map(lambda x: netlib.http.url.quote(x, safe=""), components) + components = map(lambda x: mitmproxy.net.http.url.quote(x, safe=""), components) path = "/" + "/".join(components) _, _, _, params, query, fragment = urllib.parse.urlparse(self.url) self.path = urllib.parse.urlunparse(["", "", path, params, query, fragment]) @@ -347,7 +347,7 @@ def constrain_encoding(self): @property def urlencoded_form(self): """ - The URL-encoded form data as an :py:class:`~netlib.multidict.MultiDictView` object. + The URL-encoded form data as an :py:class:`~mitmproxy.net.multidict.MultiDictView` object. An empty multidict.MultiDictView if the content-type indicates non-form data or the content could not be parsed. """ @@ -360,7 +360,7 @@ def _get_urlencoded_form(self): is_valid_content_type = "application/x-www-form-urlencoded" in self.headers.get("content-type", "").lower() if is_valid_content_type: try: - return tuple(netlib.http.url.decode(self.content)) + return tuple(mitmproxy.net.http.url.decode(self.content)) except ValueError: pass return () @@ -371,7 +371,7 @@ def _set_urlencoded_form(self, form_data): This will overwrite the existing content if there is one. """ self.headers["content-type"] = "application/x-www-form-urlencoded" - self.content = netlib.http.url.encode(form_data).encode() + self.content = mitmproxy.net.http.url.encode(form_data).encode() @urlencoded_form.setter def urlencoded_form(self, value): @@ -380,7 +380,7 @@ def urlencoded_form(self, value): @property def multipart_form(self): """ - The multipart form data as an :py:class:`~netlib.multidict.MultiDictView` object. + The multipart form data as an :py:class:`~mitmproxy.net.multidict.MultiDictView` object. None if the content-type indicates non-form data. """ return multidict.MultiDictView( diff --git a/netlib/http/response.py b/mitmproxy/net/http/response.py similarity index 95% rename from netlib/http/response.py rename to mitmproxy/net/http/response.py index 4d1d5d24b1..b458a3d8a3 100644 --- a/netlib/http/response.py +++ b/mitmproxy/net/http/response.py @@ -2,10 +2,10 @@ from email.utils import parsedate_tz, formatdate, mktime_tz from mitmproxy.utils import human from mitmproxy.types import multidict -from netlib.http import cookies -from netlib.http import headers as nheaders -from netlib.http import message -from netlib.http import status_codes +from mitmproxy.net.http import cookies +from mitmproxy.net.http import headers as nheaders +from mitmproxy.net.http import message +from mitmproxy.net.http import status_codes from typing import AnyStr from typing import Dict from typing import Iterable @@ -131,7 +131,7 @@ def reason(self, reason): def cookies(self) -> multidict.MultiDictView: """ The response cookies. A possibly empty - :py:class:`~netlib.multidict.MultiDictView`, where the keys are cookie + :py:class:`~mitmproxy.net.multidict.MultiDictView`, where the keys are cookie name strings, and values are (value, attr) tuples. Value is a string, and attr is an MultiDictView containing cookie attributes. Within attrs, unary attributes (e.g. HTTPOnly) are indicated by a Null value. diff --git a/netlib/http/status_codes.py b/mitmproxy/net/http/status_codes.py similarity index 100% rename from netlib/http/status_codes.py rename to mitmproxy/net/http/status_codes.py diff --git a/netlib/http/url.py b/mitmproxy/net/http/url.py similarity index 99% rename from netlib/http/url.py rename to mitmproxy/net/http/url.py index 3ca5812028..ff3d526419 100644 --- a/netlib/http/url.py +++ b/mitmproxy/net/http/url.py @@ -2,7 +2,7 @@ from typing import Sequence from typing import Tuple -from netlib import check +from mitmproxy.net import check # PY2 workaround diff --git a/netlib/http/user_agents.py b/mitmproxy/net/http/user_agents.py similarity index 100% rename from netlib/http/user_agents.py rename to mitmproxy/net/http/user_agents.py diff --git a/netlib/socks.py b/mitmproxy/net/socks.py similarity index 99% rename from netlib/socks.py rename to mitmproxy/net/socks.py index 377308a810..115949f5d5 100644 --- a/netlib/socks.py +++ b/mitmproxy/net/socks.py @@ -2,8 +2,8 @@ import array import ipaddress -from netlib import tcp -from netlib import check +from mitmproxy.net import tcp +from mitmproxy.net import check from mitmproxy.types import bidi diff --git a/netlib/tcp.py b/mitmproxy/net/tcp.py similarity index 100% rename from netlib/tcp.py rename to mitmproxy/net/tcp.py diff --git a/netlib/websockets/__init__.py b/mitmproxy/net/websockets/__init__.py similarity index 100% rename from netlib/websockets/__init__.py rename to mitmproxy/net/websockets/__init__.py diff --git a/netlib/websockets/frame.py b/mitmproxy/net/websockets/frame.py similarity index 99% rename from netlib/websockets/frame.py rename to mitmproxy/net/websockets/frame.py index bc4ae43a15..bd5f67ddcc 100644 --- a/netlib/websockets/frame.py +++ b/mitmproxy/net/websockets/frame.py @@ -2,7 +2,7 @@ import struct import io -from netlib import tcp +from mitmproxy.net import tcp from mitmproxy.utils import strutils from mitmproxy.utils import bits from mitmproxy.utils import human diff --git a/netlib/websockets/masker.py b/mitmproxy/net/websockets/masker.py similarity index 100% rename from netlib/websockets/masker.py rename to mitmproxy/net/websockets/masker.py diff --git a/netlib/websockets/utils.py b/mitmproxy/net/websockets/utils.py similarity index 98% rename from netlib/websockets/utils.py rename to mitmproxy/net/websockets/utils.py index 980436622c..d0b168ce7d 100644 --- a/netlib/websockets/utils.py +++ b/mitmproxy/net/websockets/utils.py @@ -8,7 +8,7 @@ import hashlib import os -from netlib import http +from mitmproxy.net import http from mitmproxy.utils import strutils MAGIC = b'258EAFA5-E914-47DA-95CA-C5AB0DC85B11' diff --git a/netlib/wsgi.py b/mitmproxy/net/wsgi.py similarity index 98% rename from netlib/wsgi.py rename to mitmproxy/net/wsgi.py index 5a54cd706d..b2705ea1d7 100644 --- a/netlib/wsgi.py +++ b/mitmproxy/net/wsgi.py @@ -3,8 +3,8 @@ import urllib import io -from netlib import http -from netlib import tcp +from mitmproxy.net import http +from mitmproxy.net import tcp from mitmproxy.utils import strutils diff --git a/mitmproxy/proxy/config.py b/mitmproxy/proxy/config.py index 86b68ee57a..7df9e69297 100644 --- a/mitmproxy/proxy/config.py +++ b/mitmproxy/proxy/config.py @@ -11,9 +11,9 @@ from mitmproxy import exceptions from mitmproxy import options as moptions from mitmproxy import certs -from netlib import tcp -from netlib.http import authentication -from netlib.http import url +from mitmproxy.net import tcp +from mitmproxy.net.http import authentication +from mitmproxy.net.http import url CONF_BASENAME = "mitmproxy" diff --git a/mitmproxy/proxy/modes/socks_proxy.py b/mitmproxy/proxy/modes/socks_proxy.py index 175453b041..adcd8fc1db 100644 --- a/mitmproxy/proxy/modes/socks_proxy.py +++ b/mitmproxy/proxy/modes/socks_proxy.py @@ -1,6 +1,6 @@ from mitmproxy import exceptions from mitmproxy.proxy import protocol -from netlib import socks +from mitmproxy.net import socks class Socks5Proxy(protocol.Layer, protocol.ServerConnectionMixin): diff --git a/mitmproxy/proxy/protocol/http.py b/mitmproxy/proxy/protocol/http.py index 6bc06502cf..a47fb45546 100644 --- a/mitmproxy/proxy/protocol/http.py +++ b/mitmproxy/proxy/protocol/http.py @@ -6,9 +6,9 @@ from mitmproxy import flow from mitmproxy.proxy.protocol import base from mitmproxy.proxy.protocol import websockets as pwebsockets -import netlib.http -from netlib import tcp -from netlib import websockets +import mitmproxy.net.http +from mitmproxy.net import tcp +from mitmproxy.net import websockets class _HttpTransmissionLayer(base.Layer): @@ -422,13 +422,13 @@ def authenticate(self, request): self.send_response(http.make_error_response( 401, "Authentication Required", - netlib.http.Headers(**self.config.authenticator.auth_challenge_headers()) + mitmproxy.net.http.Headers(**self.config.authenticator.auth_challenge_headers()) )) else: self.send_response(http.make_error_response( 407, "Proxy Authentication Required", - netlib.http.Headers(**self.config.authenticator.auth_challenge_headers()) + mitmproxy.net.http.Headers(**self.config.authenticator.auth_challenge_headers()) )) return False return True diff --git a/mitmproxy/proxy/protocol/http1.py b/mitmproxy/proxy/protocol/http1.py index 968d324983..713c48a76a 100644 --- a/mitmproxy/proxy/protocol/http1.py +++ b/mitmproxy/proxy/protocol/http1.py @@ -1,6 +1,6 @@ from mitmproxy import http from mitmproxy.proxy.protocol import http as httpbase -from netlib.http import http1 +from mitmproxy.net.http import http1 class Http1Layer(httpbase._HttpTransmissionLayer): diff --git a/mitmproxy/proxy/protocol/http2.py b/mitmproxy/proxy/protocol/http2.py index d0b0720d88..f635e71086 100644 --- a/mitmproxy/proxy/protocol/http2.py +++ b/mitmproxy/proxy/protocol/http2.py @@ -12,10 +12,10 @@ from mitmproxy import http from mitmproxy.proxy.protocol import base from mitmproxy.proxy.protocol import http as httpbase -import netlib.http -from netlib import tcp +import mitmproxy.net.http +from mitmproxy.net import tcp from mitmproxy.types import basethread -from netlib.http import http2 +from mitmproxy.net.http import http2 class SafeH2Connection(connection.H2Connection): @@ -148,7 +148,7 @@ def _handle_event(self, event, source_conn, other_conn, is_server): return True def _handle_request_received(self, eid, event, h2_connection): - headers = netlib.http.Headers([[k, v] for k, v in event.headers]) + headers = mitmproxy.net.http.Headers([[k, v] for k, v in event.headers]) self.streams[eid] = Http2SingleStreamLayer(self, h2_connection, eid, headers) self.streams[eid].timestamp_start = time.time() self.streams[eid].no_body = (event.stream_ended is not None) @@ -162,7 +162,7 @@ def _handle_request_received(self, eid, event, h2_connection): return True def _handle_response_received(self, eid, event): - headers = netlib.http.Headers([[k, v] for k, v in event.headers]) + headers = mitmproxy.net.http.Headers([[k, v] for k, v in event.headers]) self.streams[eid].queued_data_length = 0 self.streams[eid].timestamp_start = time.time() self.streams[eid].response_headers = headers @@ -239,7 +239,7 @@ def _handle_pushed_stream_received(self, event, h2_connection): self.client_conn.h2.push_stream(parent_eid, event.pushed_stream_id, event.headers) self.client_conn.send(self.client_conn.h2.data_to_send()) - headers = netlib.http.Headers([[k, v] for k, v in event.headers]) + headers = mitmproxy.net.http.Headers([[k, v] for k, v in event.headers]) self.streams[event.pushed_stream_id] = Http2SingleStreamLayer(self, h2_connection, event.pushed_stream_id, headers) self.streams[event.pushed_stream_id].timestamp_start = time.time() self.streams[event.pushed_stream_id].pushed = True diff --git a/mitmproxy/proxy/protocol/http_replay.py b/mitmproxy/proxy/protocol/http_replay.py index 7efb0782a3..c37badd3f3 100644 --- a/mitmproxy/proxy/protocol/http_replay.py +++ b/mitmproxy/proxy/protocol/http_replay.py @@ -6,7 +6,7 @@ from mitmproxy import http from mitmproxy import flow from mitmproxy import connections -from netlib.http import http1 +from mitmproxy.net.http import http1 from mitmproxy.types import basethread diff --git a/mitmproxy/proxy/protocol/rawtcp.py b/mitmproxy/proxy/protocol/rawtcp.py index 8230c50b9b..0ec5059453 100644 --- a/mitmproxy/proxy/protocol/rawtcp.py +++ b/mitmproxy/proxy/protocol/rawtcp.py @@ -2,7 +2,7 @@ from OpenSSL import SSL -import netlib.tcp +import mitmproxy.net.tcp from mitmproxy import tcp from mitmproxy import flow from mitmproxy import exceptions @@ -31,7 +31,7 @@ def __call__(self): try: while not self.channel.should_exit.is_set(): - r = netlib.tcp.ssl_read_select(conns, 10) + r = mitmproxy.net.tcp.ssl_read_select(conns, 10) for conn in r: dst = server if conn == client else client diff --git a/mitmproxy/proxy/protocol/tls.py b/mitmproxy/proxy/protocol/tls.py index b106aa0c02..8a344faf57 100644 --- a/mitmproxy/proxy/protocol/tls.py +++ b/mitmproxy/proxy/protocol/tls.py @@ -6,7 +6,7 @@ from mitmproxy import exceptions from mitmproxy.contrib.tls import _constructs from mitmproxy.proxy.protocol import base -from netlib import check +from mitmproxy.net import check # taken from https://testssl.sh/openssl-rfc.mappping.html diff --git a/mitmproxy/proxy/protocol/websockets.py b/mitmproxy/proxy/protocol/websockets.py index f84a1dc592..ca1d05cb61 100644 --- a/mitmproxy/proxy/protocol/websockets.py +++ b/mitmproxy/proxy/protocol/websockets.py @@ -4,8 +4,8 @@ from mitmproxy import exceptions from mitmproxy.proxy.protocol import base from mitmproxy.utils import strutils -from netlib import tcp -from netlib import websockets +from mitmproxy.net import tcp +from mitmproxy.net import websockets class WebSocketsLayer(base.Layer): diff --git a/mitmproxy/proxy/server.py b/mitmproxy/proxy/server.py index 8472660acb..232d703895 100644 --- a/mitmproxy/proxy/server.py +++ b/mitmproxy/proxy/server.py @@ -8,8 +8,8 @@ from mitmproxy import log from mitmproxy.proxy import modes from mitmproxy.proxy import root_context -from netlib import tcp -from netlib.http import http1 +from mitmproxy.net import tcp +from mitmproxy.net.http import http1 class DummyServer: diff --git a/mitmproxy/test/tutils.py b/mitmproxy/test/tutils.py index fc7c0eb9d9..e925b282d6 100644 --- a/mitmproxy/test/tutils.py +++ b/mitmproxy/test/tutils.py @@ -7,8 +7,8 @@ import sys from mitmproxy.utils import data -from netlib import tcp -from netlib import http +from mitmproxy.net import tcp +from mitmproxy.net import http def treader(bytes): @@ -89,13 +89,13 @@ def __exit__(self, exc_type, exc_val, exc_tb): return True -test_data = data.Data(__name__).push("../../test/netlib") +test_data = data.Data(__name__).push("../../test/mitmproxy/net") def treq(**kwargs): """ Returns: - netlib.http.Request + mitmproxy.net.http.Request """ default = dict( first_line_format="relative", @@ -115,7 +115,7 @@ def treq(**kwargs): def tresp(**kwargs): """ Returns: - netlib.http.Response + mitmproxy.net.http.Response """ default = dict( http_version=b"HTTP/1.1", diff --git a/mitmproxy/tools/cmdline.py b/mitmproxy/tools/cmdline.py index b83694efc6..2f9ea15c66 100644 --- a/mitmproxy/tools/cmdline.py +++ b/mitmproxy/tools/cmdline.py @@ -6,7 +6,7 @@ from mitmproxy import options from mitmproxy import platform from mitmproxy.utils import human -from netlib import tcp +from mitmproxy.net import tcp from mitmproxy import version diff --git a/mitmproxy/tools/console/common.py b/mitmproxy/tools/console/common.py index 53411d17cb..90dce5aea1 100644 --- a/mitmproxy/tools/console/common.py +++ b/mitmproxy/tools/console/common.py @@ -6,7 +6,7 @@ import urwid import urwid.util -import netlib +import mitmproxy.net from mitmproxy.utils import lrucache from mitmproxy.tools.console import signals from mitmproxy import export @@ -226,7 +226,7 @@ def format_flow_data(key, scope, flow): if request.content is None: return None, "Request content is missing" if key == "h": - data += netlib.http.http1.assemble_request(request) + data += mitmproxy.net.http.http1.assemble_request(request) elif key == "c": data += request.get_content(strict=False) else: @@ -240,7 +240,7 @@ def format_flow_data(key, scope, flow): if response.content is None: return None, "Response content is missing" if key == "h": - data += netlib.http.http1.assemble_response(response) + data += mitmproxy.net.http.http1.assemble_response(response) elif key == "c": data += response.get_content(strict=False) else: diff --git a/mitmproxy/tools/console/flowlist.py b/mitmproxy/tools/console/flowlist.py index 31624229c9..d33348a0f6 100644 --- a/mitmproxy/tools/console/flowlist.py +++ b/mitmproxy/tools/console/flowlist.py @@ -1,6 +1,6 @@ import urwid -import netlib.http.url +import mitmproxy.net.http.url from mitmproxy import exceptions from mitmproxy.tools.console import common from mitmproxy.tools.console import signals @@ -325,7 +325,7 @@ def get_url(self, method): ) def new_request(self, url, method): - parts = netlib.http.url.parse(str(url)) + parts = mitmproxy.net.http.url.parse(str(url)) if not parts: signals.status_message.send(message="Invalid Url") return diff --git a/mitmproxy/tools/console/flowview.py b/mitmproxy/tools/console/flowview.py index afebf44e8d..4e886ee47a 100644 --- a/mitmproxy/tools/console/flowview.py +++ b/mitmproxy/tools/console/flowview.py @@ -16,8 +16,8 @@ from mitmproxy.tools.console import signals from mitmproxy.tools.console import tabs from mitmproxy import export -from netlib.http import Headers -from netlib.http import status_codes +from mitmproxy.net.http import Headers +from mitmproxy.net.http import status_codes class SearchError(Exception): diff --git a/mitmproxy/tools/console/grideditor/col_subgrid.py b/mitmproxy/tools/console/grideditor/col_subgrid.py index 3147e63d0f..4db374620d 100644 --- a/mitmproxy/tools/console/grideditor/col_subgrid.py +++ b/mitmproxy/tools/console/grideditor/col_subgrid.py @@ -1,7 +1,7 @@ import urwid from mitmproxy.tools.console.grideditor import base from mitmproxy.tools.console import signals -from netlib.http import cookies +from mitmproxy.net.http import cookies class Column(base.Column): diff --git a/mitmproxy/tools/console/grideditor/editors.py b/mitmproxy/tools/console/grideditor/editors.py index 64361af742..5e3f3d42dc 100644 --- a/mitmproxy/tools/console/grideditor/editors.py +++ b/mitmproxy/tools/console/grideditor/editors.py @@ -9,7 +9,7 @@ from mitmproxy.tools.console.grideditor import col_text from mitmproxy.tools.console.grideditor import col_subgrid from mitmproxy.tools.console import signals -from netlib.http import user_agents +from mitmproxy.net.http import user_agents class QueryEditor(base.GridEditor): diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py index 7ff0026eb0..af43c53be9 100644 --- a/mitmproxy/tools/console/master.py +++ b/mitmproxy/tools/console/master.py @@ -37,7 +37,7 @@ from mitmproxy.flowfilter import FMarked from mitmproxy.utils import strutils -from netlib import tcp +from mitmproxy.net import tcp EVENTLOG_SIZE = 500 diff --git a/mitmproxy/tools/console/statusbar.py b/mitmproxy/tools/console/statusbar.py index ac41b213d3..74382677a7 100644 --- a/mitmproxy/tools/console/statusbar.py +++ b/mitmproxy/tools/console/statusbar.py @@ -2,7 +2,7 @@ import urwid -import netlib.http.url +import mitmproxy.net.http.url from mitmproxy.tools.console import common from mitmproxy.tools.console import pathedit from mitmproxy.tools.console import signals @@ -208,7 +208,7 @@ def get_status(self): if self.master.options.mode in ["reverse", "upstream"]: dst = self.master.server.config.upstream_server - r.append("[dest:%s]" % netlib.http.url.unparse( + r.append("[dest:%s]" % mitmproxy.net.http.url.unparse( dst.scheme, dst.address.host, dst.address.port diff --git a/mitmproxy/tools/dump.py b/mitmproxy/tools/dump.py index 47f6930399..e92482f396 100644 --- a/mitmproxy/tools/dump.py +++ b/mitmproxy/tools/dump.py @@ -8,7 +8,7 @@ from mitmproxy import options from mitmproxy import master from mitmproxy.addons import dumper, termlog -from netlib import tcp +from mitmproxy.net import tcp class DumpError(Exception): diff --git a/mitmproxy/tools/web/master.py b/mitmproxy/tools/web/master.py index 2bca45552d..619582f341 100644 --- a/mitmproxy/tools/web/master.py +++ b/mitmproxy/tools/web/master.py @@ -13,7 +13,7 @@ from mitmproxy import options from mitmproxy import master from mitmproxy.tools.web import app -from netlib.http import authentication +from mitmproxy.net.http import authentication class Stop(Exception): diff --git a/mitmproxy/utils/debug.py b/mitmproxy/utils/debug.py index 147fe4b13d..ac8fedd7b3 100644 --- a/mitmproxy/utils/debug.py +++ b/mitmproxy/utils/debug.py @@ -84,7 +84,7 @@ def dump_info(signal=None, frame=None, file=sys.stdout, testing=False): # pragm d = {} for i in gc.get_objects(): t = str(type(i)) - if "mitmproxy" in t or "netlib" in t: + if "mitmproxy" in t: d[t] = d.setdefault(t, 0) + 1 itms = list(d.items()) itms.sort(key=lambda x: x[1]) diff --git a/mitmproxy/utils/version_check.py b/mitmproxy/utils/version_check.py index 547c031c81..4cf2b9e604 100644 --- a/mitmproxy/utils/version_check.py +++ b/mitmproxy/utils/version_check.py @@ -1,7 +1,6 @@ """ -Having installed a wrong version of pyOpenSSL or netlib is unfortunately a -very common source of error. Check before every start that both versions -are somewhat okay. +Having installed a wrong version of pyOpenSSL is unfortunately a very common +source of error. Check before every start that both versions are somewhat okay. """ import sys import inspect diff --git a/netlib/http/__init__.py b/netlib/http/__init__.py deleted file mode 100644 index 315f61ac94..0000000000 --- a/netlib/http/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -from netlib.http.request import Request -from netlib.http.response import Response -from netlib.http.message import Message -from netlib.http.headers import Headers, parse_content_type -from netlib.http.message import decoded -from netlib.http import http1, http2, status_codes, multipart - -__all__ = [ - "Request", - "Response", - "Message", - "Headers", "parse_content_type", - "decoded", - "http1", "http2", "status_codes", "multipart", -] diff --git a/netlib/http/http2/__init__.py b/netlib/http/http2/__init__.py deleted file mode 100644 index 20cc63a026..0000000000 --- a/netlib/http/http2/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from netlib.http.http2.framereader import read_raw_frame, parse_frame -from netlib.http.http2.utils import parse_headers - -__all__ = [ - "read_raw_frame", - "parse_frame", - "parse_headers", -] diff --git a/pathod/language/http.py b/pathod/language/http.py index 32f990bbff..8fcf9edc76 100644 --- a/pathod/language/http.py +++ b/pathod/language/http.py @@ -2,12 +2,12 @@ import pyparsing as pp -from netlib.http import url -import netlib.websockets -from netlib.http import status_codes, user_agents +from mitmproxy.net.http import url +import mitmproxy.net.websockets +from mitmproxy.net.http import status_codes, user_agents from . import base, exceptions, actions, message -# TODO: use netlib.semantics.protocol assemble method, +# TODO: use mitmproxy.net.semantics.protocol assemble method, # instead of duplicating the HTTP on-the-wire representation here. # see http2 language for an example @@ -198,7 +198,7 @@ def resolve(self, settings, msg=None): 1, StatusCode(101) ) - headers = netlib.websockets.server_handshake_headers( + headers = mitmproxy.net.websockets.server_handshake_headers( settings.websocket_key ) for i in headers.fields: @@ -310,7 +310,7 @@ def resolve(self, settings, msg=None): 1, Method("get") ) - for i in netlib.websockets.client_handshake_headers().fields: + for i in mitmproxy.net.websockets.client_handshake_headers().fields: if not get_header(i[0], self.headers): tokens.append( Header( diff --git a/pathod/language/http2.py b/pathod/language/http2.py index 35fc5ba80c..08c5f6d779 100644 --- a/pathod/language/http2.py +++ b/pathod/language/http2.py @@ -1,7 +1,7 @@ import pyparsing as pp -from netlib import http -from netlib.http import user_agents, Headers +from mitmproxy.net import http +from mitmproxy.net.http import user_agents, Headers from . import base, message """ diff --git a/pathod/language/websockets.py b/pathod/language/websockets.py index d2291f8228..a237381cf5 100644 --- a/pathod/language/websockets.py +++ b/pathod/language/websockets.py @@ -1,6 +1,6 @@ import random import string -import netlib.websockets +import mitmproxy.net.websockets from mitmproxy.utils import strutils import pyparsing as pp from . import base, generators, actions, message @@ -14,12 +14,12 @@ class WF(base.CaselessLiteral): class OpCode(base.IntField): names = { - "continue": netlib.websockets.OPCODE.CONTINUE, - "text": netlib.websockets.OPCODE.TEXT, - "binary": netlib.websockets.OPCODE.BINARY, - "close": netlib.websockets.OPCODE.CLOSE, - "ping": netlib.websockets.OPCODE.PING, - "pong": netlib.websockets.OPCODE.PONG, + "continue": mitmproxy.net.websockets.OPCODE.CONTINUE, + "text": mitmproxy.net.websockets.OPCODE.TEXT, + "binary": mitmproxy.net.websockets.OPCODE.BINARY, + "close": mitmproxy.net.websockets.OPCODE.CLOSE, + "ping": mitmproxy.net.websockets.OPCODE.PING, + "pong": mitmproxy.net.websockets.OPCODE.PONG, } max = 15 preamble = "c" @@ -215,11 +215,11 @@ def values(self, settings): v = getattr(self, i, None) if v is not None: frameparts[i] = v.value - frame = netlib.websockets.FrameHeader(**frameparts) + frame = mitmproxy.net.websockets.FrameHeader(**frameparts) vals = [bytes(frame)] if bodygen: if frame.masking_key and not self.rawbody: - masker = netlib.websockets.Masker(frame.masking_key) + masker = mitmproxy.net.websockets.Masker(frame.masking_key) vals.append( generators.TransformGenerator( bodygen, diff --git a/pathod/pathoc.py b/pathod/pathoc.py index 0978277add..066c330c0d 100644 --- a/pathod/pathoc.py +++ b/pathod/pathoc.py @@ -13,12 +13,12 @@ from mitmproxy.test.tutils import treq from mitmproxy.utils import strutils -from netlib import tcp +from mitmproxy.net import tcp from mitmproxy import certs -from netlib import websockets -from netlib import socks +from mitmproxy.net import websockets +from mitmproxy.net import socks from mitmproxy import exceptions -from netlib.http import http1 +from mitmproxy.net.http import http1 from mitmproxy.types import basethread from pathod import log diff --git a/pathod/pathoc_cmdline.py b/pathod/pathoc_cmdline.py index 2b4b9f9ce0..3b738d47ae 100644 --- a/pathod/pathoc_cmdline.py +++ b/pathod/pathoc_cmdline.py @@ -3,9 +3,9 @@ import os import os.path -from netlib import tcp +from mitmproxy.net import tcp from mitmproxy import version -from netlib.http import user_agents +from mitmproxy.net.http import user_agents from . import pathoc, language diff --git a/pathod/pathod.py b/pathod/pathod.py index 746998c550..a8658361df 100644 --- a/pathod/pathod.py +++ b/pathod/pathod.py @@ -4,9 +4,9 @@ import sys import threading -from netlib import tcp +from mitmproxy.net import tcp from mitmproxy import certs as mcerts -from netlib import websockets +from mitmproxy.net import websockets from mitmproxy import version import urllib diff --git a/pathod/pathod_cmdline.py b/pathod/pathod_cmdline.py index 8d6ee2b6e2..ef1e983ff6 100644 --- a/pathod/pathod_cmdline.py +++ b/pathod/pathod_cmdline.py @@ -4,7 +4,7 @@ import os.path import re -from netlib import tcp +from mitmproxy.net import tcp from mitmproxy.utils import human from mitmproxy import version from . import pathod diff --git a/pathod/protocols/http.py b/pathod/protocols/http.py index a20a58a1d4..4387b4fb1c 100644 --- a/pathod/protocols/http.py +++ b/pathod/protocols/http.py @@ -1,6 +1,6 @@ from mitmproxy import version from mitmproxy import exceptions -from netlib.http import http1 +from mitmproxy.net.http import http1 from .. import language diff --git a/pathod/protocols/http2.py b/pathod/protocols/http2.py index 838469d6fe..118163d28d 100644 --- a/pathod/protocols/http2.py +++ b/pathod/protocols/http2.py @@ -4,10 +4,10 @@ import hyperframe.frame from hpack.hpack import Encoder, Decoder -from netlib.http import http2 -import netlib.http.headers -import netlib.http.response -import netlib.http.request +from mitmproxy.net.http import http2 +import mitmproxy.net.http.headers +import mitmproxy.net.http.response +import mitmproxy.net.http.request from mitmproxy.types import bidi from .. import language @@ -100,7 +100,7 @@ def read_request( first_line_format, method, scheme, host, port, path = http2.parse_headers(headers) - request = netlib.http.request.Request( + request = mitmproxy.net.http.request.Request( first_line_format, method, scheme, @@ -148,7 +148,7 @@ def read_response( else: timestamp_end = None - response = netlib.http.response.Response( + response = mitmproxy.net.http.response.Response( b"HTTP/2.0", int(headers.get(':status', 502)), b'', @@ -162,15 +162,15 @@ def read_response( return response def assemble(self, message): - if isinstance(message, netlib.http.request.Request): + if isinstance(message, mitmproxy.net.http.request.Request): return self.assemble_request(message) - elif isinstance(message, netlib.http.response.Response): + elif isinstance(message, mitmproxy.net.http.response.Response): return self.assemble_response(message) else: raise ValueError("HTTP message not supported.") def assemble_request(self, request): - assert isinstance(request, netlib.http.request.Request) + assert isinstance(request, mitmproxy.net.http.request.Request) authority = self.tcp_handler.sni if self.tcp_handler.sni else self.tcp_handler.address.host if self.tcp_handler.address.port != 443: @@ -194,7 +194,7 @@ def assemble_request(self, request): self._create_body(request.body, stream_id))) def assemble_response(self, response): - assert isinstance(response, netlib.http.response.Response) + assert isinstance(response, mitmproxy.net.http.response.Response) headers = response.headers.copy() @@ -394,7 +394,7 @@ def _receive_transmission(self, stream_id=None, include_body=True): else: self._handle_unexpected_frame(frm) - headers = netlib.http.headers.Headers( + headers = mitmproxy.net.http.headers.Headers( [[k, v] for k, v in self.decoder.decode(header_blocks, raw=True)] ) diff --git a/pathod/protocols/websockets.py b/pathod/protocols/websockets.py index 585a48e3b5..00ae5aa888 100644 --- a/pathod/protocols/websockets.py +++ b/pathod/protocols/websockets.py @@ -1,6 +1,6 @@ import time -from netlib import websockets +from mitmproxy.net import websockets from pathod import language from mitmproxy import exceptions diff --git a/release/README.mkd b/release/README.mkd index db2ef970cf..c550543167 100644 --- a/release/README.mkd +++ b/release/README.mkd @@ -7,7 +7,7 @@ - Only if an emergency bugfix is needed, we push a new `0.x.y` bugfix release for a single project. This matches with what we do in `setup.py`: - "netlib>=%s, <%s" % (version.MINORVERSION, version.NEXT_MINORVERSION) + "mitmproxy>=%s, <%s" % (version.MINORVERSION, version.NEXT_MINORVERSION) # Release Checklist diff --git a/release/rtool.py b/release/rtool.py index 3ed9157e07..fbca40e23d 100755 --- a/release/rtool.py +++ b/release/rtool.py @@ -48,7 +48,7 @@ def Archive(name): VENV_PYINSTALLER = join(VENV_DIR, VENV_BIN, "pyinstaller") # Project Configuration -VERSION_FILE = join(ROOT_DIR, "netlib", "version.py") +VERSION_FILE = join(ROOT_DIR, "mitmproxy", "version.py") PROJECT_NAME = "mitmproxy" PYTHON_VERSION = "py2.py3" BDISTS = { diff --git a/setup.py b/setup.py index 9981ea6cfd..1351ba73a9 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,6 @@ packages=find_packages(include=[ "mitmproxy", "mitmproxy.*", "pathod", "pathod.*", - "netlib", "netlib.*" ]), include_package_data=True, entry_points={ diff --git a/test/netlib/__init__.py b/test/mitmproxy/net/__init__.py similarity index 100% rename from test/netlib/__init__.py rename to test/mitmproxy/net/__init__.py diff --git a/test/netlib/data/clientcert/.gitignore b/test/mitmproxy/net/data/clientcert/.gitignore similarity index 100% rename from test/netlib/data/clientcert/.gitignore rename to test/mitmproxy/net/data/clientcert/.gitignore diff --git a/test/netlib/data/clientcert/client.cnf b/test/mitmproxy/net/data/clientcert/client.cnf similarity index 100% rename from test/netlib/data/clientcert/client.cnf rename to test/mitmproxy/net/data/clientcert/client.cnf diff --git a/test/netlib/data/clientcert/client.pem b/test/mitmproxy/net/data/clientcert/client.pem similarity index 100% rename from test/netlib/data/clientcert/client.pem rename to test/mitmproxy/net/data/clientcert/client.pem diff --git a/test/netlib/data/clientcert/make b/test/mitmproxy/net/data/clientcert/make similarity index 100% rename from test/netlib/data/clientcert/make rename to test/mitmproxy/net/data/clientcert/make diff --git a/test/netlib/data/dercert b/test/mitmproxy/net/data/dercert similarity index 100% rename from test/netlib/data/dercert rename to test/mitmproxy/net/data/dercert diff --git a/test/netlib/data/dhparam.pem b/test/mitmproxy/net/data/dhparam.pem similarity index 100% rename from test/netlib/data/dhparam.pem rename to test/mitmproxy/net/data/dhparam.pem diff --git a/test/netlib/data/htpasswd b/test/mitmproxy/net/data/htpasswd similarity index 100% rename from test/netlib/data/htpasswd rename to test/mitmproxy/net/data/htpasswd diff --git a/test/netlib/data/server.crt b/test/mitmproxy/net/data/server.crt similarity index 100% rename from test/netlib/data/server.crt rename to test/mitmproxy/net/data/server.crt diff --git a/test/netlib/data/server.key b/test/mitmproxy/net/data/server.key similarity index 100% rename from test/netlib/data/server.key rename to test/mitmproxy/net/data/server.key diff --git a/test/netlib/data/text_cert b/test/mitmproxy/net/data/text_cert similarity index 100% rename from test/netlib/data/text_cert rename to test/mitmproxy/net/data/text_cert diff --git a/test/netlib/data/text_cert_2 b/test/mitmproxy/net/data/text_cert_2 similarity index 100% rename from test/netlib/data/text_cert_2 rename to test/mitmproxy/net/data/text_cert_2 diff --git a/test/netlib/data/text_cert_weird1 b/test/mitmproxy/net/data/text_cert_weird1 similarity index 100% rename from test/netlib/data/text_cert_weird1 rename to test/mitmproxy/net/data/text_cert_weird1 diff --git a/test/netlib/data/verificationcerts/9da13359.0 b/test/mitmproxy/net/data/verificationcerts/9da13359.0 similarity index 100% rename from test/netlib/data/verificationcerts/9da13359.0 rename to test/mitmproxy/net/data/verificationcerts/9da13359.0 diff --git a/test/netlib/data/verificationcerts/generate.py b/test/mitmproxy/net/data/verificationcerts/generate.py similarity index 100% rename from test/netlib/data/verificationcerts/generate.py rename to test/mitmproxy/net/data/verificationcerts/generate.py diff --git a/test/netlib/data/verificationcerts/self-signed.crt b/test/mitmproxy/net/data/verificationcerts/self-signed.crt similarity index 100% rename from test/netlib/data/verificationcerts/self-signed.crt rename to test/mitmproxy/net/data/verificationcerts/self-signed.crt diff --git a/test/netlib/data/verificationcerts/self-signed.key b/test/mitmproxy/net/data/verificationcerts/self-signed.key similarity index 100% rename from test/netlib/data/verificationcerts/self-signed.key rename to test/mitmproxy/net/data/verificationcerts/self-signed.key diff --git a/test/netlib/data/verificationcerts/trusted-leaf.crt b/test/mitmproxy/net/data/verificationcerts/trusted-leaf.crt similarity index 100% rename from test/netlib/data/verificationcerts/trusted-leaf.crt rename to test/mitmproxy/net/data/verificationcerts/trusted-leaf.crt diff --git a/test/netlib/data/verificationcerts/trusted-leaf.key b/test/mitmproxy/net/data/verificationcerts/trusted-leaf.key similarity index 100% rename from test/netlib/data/verificationcerts/trusted-leaf.key rename to test/mitmproxy/net/data/verificationcerts/trusted-leaf.key diff --git a/test/netlib/data/verificationcerts/trusted-root.crt b/test/mitmproxy/net/data/verificationcerts/trusted-root.crt similarity index 100% rename from test/netlib/data/verificationcerts/trusted-root.crt rename to test/mitmproxy/net/data/verificationcerts/trusted-root.crt diff --git a/test/netlib/data/verificationcerts/trusted-root.key b/test/mitmproxy/net/data/verificationcerts/trusted-root.key similarity index 100% rename from test/netlib/data/verificationcerts/trusted-root.key rename to test/mitmproxy/net/data/verificationcerts/trusted-root.key diff --git a/test/netlib/data/verificationcerts/trusted-root.srl b/test/mitmproxy/net/data/verificationcerts/trusted-root.srl similarity index 100% rename from test/netlib/data/verificationcerts/trusted-root.srl rename to test/mitmproxy/net/data/verificationcerts/trusted-root.srl diff --git a/test/netlib/http/__init__.py b/test/mitmproxy/net/http/__init__.py similarity index 100% rename from test/netlib/http/__init__.py rename to test/mitmproxy/net/http/__init__.py diff --git a/test/netlib/http/http1/__init__.py b/test/mitmproxy/net/http/http1/__init__.py similarity index 100% rename from test/netlib/http/http1/__init__.py rename to test/mitmproxy/net/http/http1/__init__.py diff --git a/test/netlib/http/http1/test_assemble.py b/test/mitmproxy/net/http/http1/test_assemble.py similarity index 97% rename from test/netlib/http/http1/test_assemble.py rename to test/mitmproxy/net/http/http1/test_assemble.py index dac5fdada5..e80376e81e 100644 --- a/test/netlib/http/http1/test_assemble.py +++ b/test/mitmproxy/net/http/http1/test_assemble.py @@ -1,6 +1,6 @@ from mitmproxy import exceptions -from netlib.http import Headers -from netlib.http.http1.assemble import ( +from mitmproxy.net.http import Headers +from mitmproxy.net.http.http1.assemble import ( assemble_request, assemble_request_head, assemble_response, assemble_response_head, _assemble_request_line, _assemble_request_headers, _assemble_response_headers, diff --git a/test/netlib/http/http1/test_read.py b/test/mitmproxy/net/http/http1/test_read.py similarity index 99% rename from test/netlib/http/http1/test_read.py rename to test/mitmproxy/net/http/http1/test_read.py index eb96968cef..20997259f9 100644 --- a/test/netlib/http/http1/test_read.py +++ b/test/mitmproxy/net/http/http1/test_read.py @@ -3,8 +3,8 @@ import pytest from mitmproxy import exceptions -from netlib.http import Headers -from netlib.http.http1.read import ( +from mitmproxy.net.http import Headers +from mitmproxy.net.http.http1.read import ( read_request, read_response, read_request_head, read_response_head, read_body, connection_close, expected_http_body_size, _get_first_line, _read_request_line, _parse_authority_form, _read_response_line, _check_http_version, diff --git a/test/netlib/http/http2/__init__.py b/test/mitmproxy/net/http/http2/__init__.py similarity index 100% rename from test/netlib/http/http2/__init__.py rename to test/mitmproxy/net/http/http2/__init__.py diff --git a/test/netlib/http/http2/test_framereader.py b/test/mitmproxy/net/http/http2/test_framereader.py similarity index 100% rename from test/netlib/http/http2/test_framereader.py rename to test/mitmproxy/net/http/http2/test_framereader.py diff --git a/test/netlib/http/test_authentication.py b/test/mitmproxy/net/http/test_authentication.py similarity index 98% rename from test/netlib/http/test_authentication.py rename to test/mitmproxy/net/http/test_authentication.py index 5e04bbc5c8..11b6e2e0eb 100644 --- a/test/netlib/http/test_authentication.py +++ b/test/mitmproxy/net/http/test_authentication.py @@ -1,7 +1,7 @@ import binascii from mitmproxy.test import tutils -from netlib.http import authentication, Headers +from mitmproxy.net.http import authentication, Headers def test_parse_http_basic_auth(): diff --git a/test/netlib/http/test_cookies.py b/test/mitmproxy/net/http/test_cookies.py similarity index 99% rename from test/netlib/http/test_cookies.py rename to test/mitmproxy/net/http/test_cookies.py index ca10a69c32..8c9c0c3256 100644 --- a/test/netlib/http/test_cookies.py +++ b/test/mitmproxy/net/http/test_cookies.py @@ -1,6 +1,6 @@ import time -from netlib.http import cookies +from mitmproxy.net.http import cookies from mitmproxy.test.tutils import raises import mock diff --git a/test/netlib/http/test_encoding.py b/test/mitmproxy/net/http/test_encoding.py similarity index 98% rename from test/netlib/http/test_encoding.py rename to test/mitmproxy/net/http/test_encoding.py index 8960070966..d8fa5e7680 100644 --- a/test/netlib/http/test_encoding.py +++ b/test/mitmproxy/net/http/test_encoding.py @@ -1,7 +1,7 @@ import mock import pytest -from netlib.http import encoding +from mitmproxy.net.http import encoding from mitmproxy.test import tutils diff --git a/test/netlib/http/test_headers.py b/test/mitmproxy/net/http/test_headers.py similarity index 97% rename from test/netlib/http/test_headers.py rename to test/mitmproxy/net/http/test_headers.py index cac77d573d..8e0f770d70 100644 --- a/test/netlib/http/test_headers.py +++ b/test/mitmproxy/net/http/test_headers.py @@ -1,6 +1,6 @@ import collections -from netlib.http.headers import Headers, parse_content_type, assemble_content_type +from mitmproxy.net.http.headers import Headers, parse_content_type, assemble_content_type from mitmproxy.test.tutils import raises diff --git a/test/netlib/http/test_message.py b/test/mitmproxy/net/http/test_message.py similarity index 99% rename from test/netlib/http/test_message.py rename to test/mitmproxy/net/http/test_message.py index 2bc8824fcc..69d029d9c3 100644 --- a/test/netlib/http/test_message.py +++ b/test/mitmproxy/net/http/test_message.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from mitmproxy.test import tutils -from netlib import http +from mitmproxy.net import http def _test_passthrough_attr(message, attr): diff --git a/test/netlib/http/test_multipart.py b/test/mitmproxy/net/http/test_multipart.py similarity index 87% rename from test/netlib/http/test_multipart.py rename to test/mitmproxy/net/http/test_multipart.py index 1d7e006208..68ae6bbdfb 100644 --- a/test/netlib/http/test_multipart.py +++ b/test/mitmproxy/net/http/test_multipart.py @@ -1,5 +1,5 @@ -from netlib.http import Headers -from netlib.http import multipart +from mitmproxy.net.http import Headers +from mitmproxy.net.http import multipart def test_decode(): diff --git a/test/netlib/http/test_request.py b/test/mitmproxy/net/http/test_request.py similarity index 99% rename from test/netlib/http/test_request.py rename to test/mitmproxy/net/http/test_request.py index ecfc1ba6c2..9c0ec333c4 100644 --- a/test/netlib/http/test_request.py +++ b/test/mitmproxy/net/http/test_request.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from netlib.http import Headers +from mitmproxy.net.http import Headers from mitmproxy.test.tutils import treq, raises from .test_message import _test_decoded_attr, _test_passthrough_attr diff --git a/test/netlib/http/test_response.py b/test/mitmproxy/net/http/test_response.py similarity index 97% rename from test/netlib/http/test_response.py rename to test/mitmproxy/net/http/test_response.py index 4a6fac62de..239fb6ef7e 100644 --- a/test/netlib/http/test_response.py +++ b/test/mitmproxy/net/http/test_response.py @@ -2,9 +2,9 @@ import time -from netlib.http import Headers -from netlib.http import Response -from netlib.http.cookies import CookieAttrs +from mitmproxy.net.http import Headers +from mitmproxy.net.http import Response +from mitmproxy.net.http.cookies import CookieAttrs from mitmproxy.test.tutils import raises, tresp from .test_message import _test_passthrough_attr, _test_decoded_attr diff --git a/test/netlib/http/test_status_codes.py b/test/mitmproxy/net/http/test_status_codes.py similarity index 73% rename from test/netlib/http/test_status_codes.py rename to test/mitmproxy/net/http/test_status_codes.py index 9fea6b7074..098f8eef99 100644 --- a/test/netlib/http/test_status_codes.py +++ b/test/mitmproxy/net/http/test_status_codes.py @@ -1,4 +1,4 @@ -from netlib.http import status_codes +from mitmproxy.net.http import status_codes def test_simple(): diff --git a/test/netlib/http/test_url.py b/test/mitmproxy/net/http/test_url.py similarity index 98% rename from test/netlib/http/test_url.py rename to test/mitmproxy/net/http/test_url.py index 7cea6c5800..94b2eaccc0 100644 --- a/test/netlib/http/test_url.py +++ b/test/mitmproxy/net/http/test_url.py @@ -1,5 +1,5 @@ from mitmproxy.test import tutils -from netlib.http import url +from mitmproxy.net.http import url def test_parse(): diff --git a/test/netlib/http/test_user_agents.py b/test/mitmproxy/net/http/test_user_agents.py similarity index 75% rename from test/netlib/http/test_user_agents.py rename to test/mitmproxy/net/http/test_user_agents.py index 0bf1bba7fd..9e39144703 100644 --- a/test/netlib/http/test_user_agents.py +++ b/test/mitmproxy/net/http/test_user_agents.py @@ -1,4 +1,4 @@ -from netlib.http import user_agents +from mitmproxy.net.http import user_agents def test_get_shortcut(): diff --git a/test/netlib/test_check.py b/test/mitmproxy/net/test_check.py similarity index 87% rename from test/netlib/test_check.py rename to test/mitmproxy/net/test_check.py index 6a1388f4d0..18a50157fa 100644 --- a/test/netlib/test_check.py +++ b/test/mitmproxy/net/test_check.py @@ -1,6 +1,6 @@ # coding=utf-8 -from netlib import check +from mitmproxy.net import check def test_is_valid_host(): diff --git a/test/netlib/test_imports.py b/test/mitmproxy/net/test_imports.py similarity index 100% rename from test/netlib/test_imports.py rename to test/mitmproxy/net/test_imports.py diff --git a/test/netlib/test_socks.py b/test/mitmproxy/net/test_socks.py similarity index 98% rename from test/netlib/test_socks.py rename to test/mitmproxy/net/test_socks.py index 0603f34b39..b6551faa33 100644 --- a/test/netlib/test_socks.py +++ b/test/mitmproxy/net/test_socks.py @@ -1,7 +1,7 @@ import ipaddress from io import BytesIO -from netlib import socks -from netlib import tcp +from mitmproxy.net import socks +from mitmproxy.net import tcp from mitmproxy.test import tutils diff --git a/test/netlib/test_tcp.py b/test/mitmproxy/net/test_tcp.py similarity index 99% rename from test/netlib/test_tcp.py rename to test/mitmproxy/net/test_tcp.py index 594ee21c25..8a7c692a3c 100644 --- a/test/netlib/test_tcp.py +++ b/test/mitmproxy/net/test_tcp.py @@ -10,7 +10,7 @@ from OpenSSL import SSL from mitmproxy import certs -from netlib import tcp +from mitmproxy.net import tcp from mitmproxy.test import tutils from mitmproxy import exceptions diff --git a/test/netlib/test_wsgi.py b/test/mitmproxy/net/test_wsgi.py similarity index 97% rename from test/netlib/test_wsgi.py rename to test/mitmproxy/net/test_wsgi.py index 5c61f81c85..b4d6b53f29 100644 --- a/test/netlib/test_wsgi.py +++ b/test/mitmproxy/net/test_wsgi.py @@ -1,7 +1,7 @@ from io import BytesIO import sys -from netlib import wsgi -from netlib.http import Headers +from mitmproxy.net import wsgi +from mitmproxy.net.http import Headers def tflow(): diff --git a/test/netlib/tools/getcertnames b/test/mitmproxy/net/tools/getcertnames similarity index 94% rename from test/netlib/tools/getcertnames rename to test/mitmproxy/net/tools/getcertnames index 0882fccd13..d64e5ff55e 100644 --- a/test/netlib/tools/getcertnames +++ b/test/mitmproxy/net/tools/getcertnames @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys sys.path.insert(0, "../../") -from netlib import tcp +from mitmproxy.net import tcp def get_remote_cert(host, port, sni): diff --git a/test/netlib/tservers.py b/test/mitmproxy/net/tservers.py similarity index 99% rename from test/netlib/tservers.py rename to test/mitmproxy/net/tservers.py index 2fae8ba62c..ba10ef5ed1 100644 --- a/test/netlib/tservers.py +++ b/test/mitmproxy/net/tservers.py @@ -3,7 +3,7 @@ import io import OpenSSL -from netlib import tcp +from mitmproxy.net import tcp from mitmproxy.test import tutils diff --git a/test/netlib/websockets/__init__.py b/test/mitmproxy/net/websockets/__init__.py similarity index 100% rename from test/netlib/websockets/__init__.py rename to test/mitmproxy/net/websockets/__init__.py diff --git a/test/netlib/websockets/test_frame.py b/test/mitmproxy/net/websockets/test_frame.py similarity index 99% rename from test/netlib/websockets/test_frame.py rename to test/mitmproxy/net/websockets/test_frame.py index 3b7c9ed4a5..198be3d577 100644 --- a/test/netlib/websockets/test_frame.py +++ b/test/mitmproxy/net/websockets/test_frame.py @@ -2,7 +2,7 @@ import codecs import pytest -from netlib import websockets +from mitmproxy.net import websockets from mitmproxy.test import tutils diff --git a/test/netlib/websockets/test_masker.py b/test/mitmproxy/net/websockets/test_masker.py similarity index 95% rename from test/netlib/websockets/test_masker.py rename to test/mitmproxy/net/websockets/test_masker.py index 23a9b87636..88360c3b4d 100644 --- a/test/netlib/websockets/test_masker.py +++ b/test/mitmproxy/net/websockets/test_masker.py @@ -1,7 +1,7 @@ import codecs import pytest -from netlib import websockets +from mitmproxy.net import websockets class TestMasker: diff --git a/test/netlib/websockets/test_utils.py b/test/mitmproxy/net/websockets/test_utils.py similarity index 98% rename from test/netlib/websockets/test_utils.py rename to test/mitmproxy/net/websockets/test_utils.py index f6f1e40a7c..6704d39d9e 100644 --- a/test/netlib/websockets/test_utils.py +++ b/test/mitmproxy/net/websockets/test_utils.py @@ -1,7 +1,7 @@ import pytest -from netlib import http -from netlib import websockets +from mitmproxy.net import http +from mitmproxy.net import websockets class TestUtils: diff --git a/test/mitmproxy/protocol/test_http1.py b/test/mitmproxy/protocol/test_http1.py index d18ff41170..43c903f370 100644 --- a/test/mitmproxy/protocol/test_http1.py +++ b/test/mitmproxy/protocol/test_http1.py @@ -1,5 +1,5 @@ -from netlib.http import http1 -from netlib.tcp import TCPClient +from mitmproxy.net.http import http1 +from mitmproxy.net.tcp import TCPClient from mitmproxy.test.tutils import treq from .. import tutils, tservers diff --git a/test/mitmproxy/protocol/test_http2.py b/test/mitmproxy/protocol/test_http2.py index b624489fe6..4629d10995 100644 --- a/test/mitmproxy/protocol/test_http2.py +++ b/test/mitmproxy/protocol/test_http2.py @@ -11,10 +11,10 @@ from mitmproxy import options from mitmproxy.proxy.config import ProxyConfig -import netlib -from ...netlib import tservers as netlib_tservers +import mitmproxy.net +from ...mitmproxy.net import tservers as net_tservers from mitmproxy import exceptions -from netlib.http import http1, http2 +from mitmproxy.net.http import http1, http2 from .. import tservers @@ -28,7 +28,7 @@ requires_alpn = pytest.mark.skipif( - not netlib.tcp.HAS_ALPN, + not mitmproxy.net.tcp.HAS_ALPN, reason='requires OpenSSL with ALPN support') @@ -37,10 +37,10 @@ # print(msg) -class _Http2ServerBase(netlib_tservers.ServerTestBase): +class _Http2ServerBase(net_tservers.ServerTestBase): ssl = dict(alpn_select=b'h2') - class handler(netlib.tcp.BaseHandler): + class handler(mitmproxy.net.tcp.BaseHandler): def handle(self): h2_conn = h2.connection.H2Connection(client_side=False, header_encoding=False) @@ -122,11 +122,11 @@ def setup(self): self.server.server.handle_server_event = self.handle_server_event def _setup_connection(self): - client = netlib.tcp.TCPClient(("127.0.0.1", self.proxy.port)) + client = mitmproxy.net.tcp.TCPClient(("127.0.0.1", self.proxy.port)) client.connect() # send CONNECT request - client.wfile.write(http1.assemble_request(netlib.http.Request( + client.wfile.write(http1.assemble_request(mitmproxy.net.http.Request( 'authority', b'CONNECT', b'', diff --git a/test/mitmproxy/protocol/test_websockets.py b/test/mitmproxy/protocol/test_websockets.py index f22e95d554..71cbb5f491 100644 --- a/test/mitmproxy/protocol/test_websockets.py +++ b/test/mitmproxy/protocol/test_websockets.py @@ -7,17 +7,17 @@ from mitmproxy import exceptions from mitmproxy.proxy.config import ProxyConfig -import netlib -from netlib import http -from ...netlib import tservers as netlib_tservers +import mitmproxy.net +from mitmproxy.net import http +from ...mitmproxy.net import tservers as net_tservers from .. import tservers -from netlib import websockets +from mitmproxy.net import websockets -class _WebSocketsServerBase(netlib_tservers.ServerTestBase): +class _WebSocketsServerBase(net_tservers.ServerTestBase): - class handler(netlib.tcp.BaseHandler): + class handler(mitmproxy.net.tcp.BaseHandler): def handle(self): try: @@ -78,7 +78,7 @@ def setup(self): self.server.server.handle_websockets = self.handle_websockets def _setup_connection(self): - client = netlib.tcp.TCPClient(("127.0.0.1", self.proxy.port)) + client = mitmproxy.net.tcp.TCPClient(("127.0.0.1", self.proxy.port)) client.connect() request = http.Request( diff --git a/test/mitmproxy/test_contentview.py b/test/mitmproxy/test_contentview.py index 2c5e1c8532..b0e77ce13c 100644 --- a/test/mitmproxy/test_contentview.py +++ b/test/mitmproxy/test_contentview.py @@ -1,7 +1,7 @@ import mock from mitmproxy.exceptions import ContentViewException -from netlib.http import Headers -from netlib.http import url +from mitmproxy.net.http import Headers +from mitmproxy.net.http import url from mitmproxy.types import multidict import mitmproxy.contentviews as cv diff --git a/test/mitmproxy/test_custom_contentview.py b/test/mitmproxy/test_custom_contentview.py index 889fb8b32a..28f7fb333e 100644 --- a/test/mitmproxy/test_custom_contentview.py +++ b/test/mitmproxy/test_custom_contentview.py @@ -1,5 +1,5 @@ import mitmproxy.contentviews as cv -from netlib.http import Headers +from mitmproxy.net.http import Headers def test_custom_views(): diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index 48193fe7d0..6972da0c7f 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -10,8 +10,8 @@ from mitmproxy import master from mitmproxy.test import tutils as netutils -from netlib.http import Headers -from netlib.http import cookies +from mitmproxy.net.http import Headers +from mitmproxy.net.http import cookies from . import tutils, mastertest diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 14899be1a9..5b9f383550 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -2,7 +2,7 @@ import io import mitmproxy.test.tutils -from netlib.http import Headers +from mitmproxy.net.http import Headers import mitmproxy.io from mitmproxy import flowfilter, options from mitmproxy.addons import state diff --git a/test/mitmproxy/test_flow_export.py b/test/mitmproxy/test_flow_export.py index 8ef2b7ee49..df0ccb77f6 100644 --- a/test/mitmproxy/test_flow_export.py +++ b/test/mitmproxy/test_flow_export.py @@ -1,7 +1,7 @@ import re import mitmproxy.test.tutils -from netlib.http import Headers +from mitmproxy.net.http import Headers from mitmproxy import export # heh from . import tutils diff --git a/test/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py index c0d978d2d5..a9d9bb878f 100644 --- a/test/mitmproxy/test_proxy.py +++ b/test/mitmproxy/test_proxy.py @@ -10,7 +10,7 @@ from mitmproxy.proxy import config from mitmproxy import exceptions from pathod import test -from netlib.http import http1 +from mitmproxy.net.http import http1 from . import tutils diff --git a/test/mitmproxy/test_server.py b/test/mitmproxy/test_server.py index f7f1344379..7dd738f443 100644 --- a/test/mitmproxy/test_server.py +++ b/test/mitmproxy/test_server.py @@ -8,14 +8,14 @@ from mitmproxy.addons import script from mitmproxy import http from mitmproxy.proxy.config import HostMatcher, parse_server_spec -import netlib.http -from netlib import tcp -from netlib import socks +import mitmproxy.net.http +from mitmproxy.net import tcp +from mitmproxy.net import socks from mitmproxy import certs from mitmproxy import exceptions -from netlib.http import authentication -from netlib.http import http1 -from netlib.tcp import Address +from mitmproxy.net.http import authentication +from mitmproxy.net.http import http1 +from mitmproxy.net.tcp import Address from mitmproxy.test.tutils import raises from pathod import pathoc from pathod import pathod @@ -297,7 +297,7 @@ def test_auth(self): h'%s'='%s' """ % ( self.server.port, - netlib.http.authentication.BasicProxyAuth.AUTH_HEADER, + mitmproxy.net.http.authentication.BasicProxyAuth.AUTH_HEADER, authentication.assemble_http_basic_auth("basic", "test", "test") )) assert ret.status_code == 202 @@ -314,7 +314,7 @@ def test_auth(self): '/p/202' h'%s'='%s' """ % ( - netlib.http.authentication.BasicWebsiteAuth.AUTH_HEADER, + mitmproxy.net.http.authentication.BasicWebsiteAuth.AUTH_HEADER, authentication.assemble_http_basic_auth("basic", "test", "test") )) assert ret.status_code == 202 @@ -438,7 +438,7 @@ def test_no_verification_w_bad_cert(self): def test_verification_w_bad_cert(self): # We only test for a single invalid cert here. # Actual testing of different root-causes (invalid hostname, expired, ...) - # is done in netlib. + # is done in mitmproxy.net. self.config.options.ssl_insecure = False r = self._request() assert r.status_code == 502 diff --git a/test/pathod/test_language_http2.py b/test/pathod/test_language_http2.py index 11e100ac85..7d3a8e60b9 100644 --- a/test/pathod/test_language_http2.py +++ b/test/pathod/test_language_http2.py @@ -1,7 +1,7 @@ import io -from netlib import tcp -from netlib.http import user_agents +from mitmproxy.net import tcp +from mitmproxy.net.http import user_agents from pathod import language from pathod.language import http2 diff --git a/test/pathod/test_language_websocket.py b/test/pathod/test_language_websocket.py index 9d533d9806..49fbd4e6db 100644 --- a/test/pathod/test_language_websocket.py +++ b/test/pathod/test_language_websocket.py @@ -1,6 +1,6 @@ from pathod import language from pathod.language import websockets -import netlib.websockets +import mitmproxy.net.websockets from . import tutils @@ -62,7 +62,7 @@ def test_nested_frame(self): def test_flags(self): wf = parse_request("wf:fin:mask:rsv1:rsv2:rsv3") - frm = netlib.websockets.Frame.from_bytes(tutils.render(wf)) + frm = mitmproxy.net.websockets.Frame.from_bytes(tutils.render(wf)) assert frm.header.fin assert frm.header.mask assert frm.header.rsv1 @@ -70,7 +70,7 @@ def test_flags(self): assert frm.header.rsv3 wf = parse_request("wf:-fin:-mask:-rsv1:-rsv2:-rsv3") - frm = netlib.websockets.Frame.from_bytes(tutils.render(wf)) + frm = mitmproxy.net.websockets.Frame.from_bytes(tutils.render(wf)) assert not frm.header.fin assert not frm.header.mask assert not frm.header.rsv1 @@ -80,15 +80,15 @@ def test_flags(self): def fr(self, spec, **kwargs): settings = language.base.Settings(**kwargs) wf = parse_request(spec) - return netlib.websockets.Frame.from_bytes(tutils.render(wf, settings)) + return mitmproxy.net.websockets.Frame.from_bytes(tutils.render(wf, settings)) def test_construction(self): assert self.fr("wf:c1").header.opcode == 1 assert self.fr("wf:c0").header.opcode == 0 assert self.fr("wf:cbinary").header.opcode ==\ - netlib.websockets.OPCODE.BINARY + mitmproxy.net.websockets.OPCODE.BINARY assert self.fr("wf:ctext").header.opcode ==\ - netlib.websockets.OPCODE.TEXT + mitmproxy.net.websockets.OPCODE.TEXT def test_rawbody(self): frm = self.fr("wf:mask:r'foo'") diff --git a/test/pathod/test_pathoc.py b/test/pathod/test_pathoc.py index 98dc9825ed..90177ff65f 100644 --- a/test/pathod/test_pathoc.py +++ b/test/pathod/test_pathoc.py @@ -1,9 +1,9 @@ import io from mock import Mock -from netlib import http -from netlib import tcp -from netlib.http import http1 +from mitmproxy.net import http +from mitmproxy.net import tcp +from mitmproxy.net.http import http1 from mitmproxy.test.tutils import raises from mitmproxy import exceptions diff --git a/test/pathod/test_pathod.py b/test/pathod/test_pathod.py index 402cd638ae..8ee7a2fd9e 100644 --- a/test/pathod/test_pathod.py +++ b/test/pathod/test_pathod.py @@ -1,7 +1,7 @@ import io from pathod import pathod -from netlib import tcp +from mitmproxy.net import tcp from mitmproxy import exceptions from . import tutils diff --git a/test/pathod/test_protocols_http2.py b/test/pathod/test_protocols_http2.py index a7303115c8..d77702a3a8 100644 --- a/test/pathod/test_protocols_http2.py +++ b/test/pathod/test_protocols_http2.py @@ -2,12 +2,12 @@ import codecs import hyperframe -from netlib import tcp, http +from mitmproxy.net import tcp, http from mitmproxy.test.tutils import raises -from netlib.http import http2 +from mitmproxy.net.http import http2 from mitmproxy import exceptions -from ..netlib import tservers as netlib_tservers +from ..mitmproxy.net import tservers as net_tservers from pathod.protocols.http2 import HTTP2StateProtocol, TCPHandler @@ -66,7 +66,7 @@ def test_perform_connection_preface_server(self, mock_client_method, mock_server assert mock_server_method.called -class TestCheckALPNMatch(netlib_tservers.ServerTestBase): +class TestCheckALPNMatch(net_tservers.ServerTestBase): handler = EchoHandler ssl = dict( alpn_select=b'h2', @@ -82,7 +82,7 @@ def test_check_alpn(self): assert protocol.check_alpn() -class TestCheckALPNMismatch(netlib_tservers.ServerTestBase): +class TestCheckALPNMismatch(net_tservers.ServerTestBase): handler = EchoHandler ssl = dict( alpn_select=None, @@ -99,7 +99,7 @@ def test_check_alpn(self): protocol.check_alpn() -class TestPerformServerConnectionPreface(netlib_tservers.ServerTestBase): +class TestPerformServerConnectionPreface(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): @@ -136,7 +136,7 @@ def test_perform_server_connection_preface(self): protocol.perform_server_connection_preface(force=True) -class TestPerformClientConnectionPreface(netlib_tservers.ServerTestBase): +class TestPerformClientConnectionPreface(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): @@ -197,7 +197,7 @@ def test_server_stream_ids(self): assert self.protocol.current_stream_id == 6 -class TestApplySettings(netlib_tservers.ServerTestBase): +class TestApplySettings(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): # check settings acknowledgement @@ -290,7 +290,7 @@ def test_create_body_multiple_frames(self): assert bytes[2] == codecs.decode('0000020001000000013432', 'hex_codec') -class TestReadRequest(netlib_tservers.ServerTestBase): +class TestReadRequest(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): @@ -320,7 +320,7 @@ def test_read_request(self): assert req.content == b'foobar' -class TestReadRequestRelative(netlib_tservers.ServerTestBase): +class TestReadRequestRelative(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): self.wfile.write( @@ -343,7 +343,7 @@ def test_asterisk_form(self): assert req.path == "*" -class TestReadRequestAbsolute(netlib_tservers.ServerTestBase): +class TestReadRequestAbsolute(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): self.wfile.write( @@ -367,7 +367,7 @@ def test_absolute_form(self): assert req.port == 22 -class TestReadResponse(netlib_tservers.ServerTestBase): +class TestReadResponse(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): self.wfile.write( @@ -396,7 +396,7 @@ def test_read_response(self): assert resp.timestamp_end -class TestReadEmptyResponse(netlib_tservers.ServerTestBase): +class TestReadEmptyResponse(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): self.wfile.write( diff --git a/test/pathod/tutils.py b/test/pathod/tutils.py index 16dec187f3..ccc3df438b 100644 --- a/test/pathod/tutils.py +++ b/test/pathod/tutils.py @@ -7,7 +7,7 @@ from mitmproxy.utils import data -from netlib import tcp +from mitmproxy.net import tcp from mitmproxy.test import tutils from pathod import language diff --git a/tox.ini b/tox.ini index 8747d2f0c5..ff1484d0e6 100644 --- a/tox.ini +++ b/tox.ini @@ -19,4 +19,4 @@ commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html [testenv:lint] deps = flake8>=2.6.2, <3.1 -commands = flake8 --jobs 8 --count mitmproxy netlib pathod examples test +commands = flake8 --jobs 8 --count mitmproxy pathod examples test