Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Commit 2ee5871

Browse files
committed
Get mitmproxy working in a thread
1 parent 54a50b4 commit 2ee5871

13 files changed

+355
-416
lines changed

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ python:
44
- 3.8
55
- 3.7
66
- 3.6
7-
- 3.5
8-
- 3.4
97

108
cache: pip
119

CONTRIBUTING.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Before you submit a pull request, check that it meets these guidelines:
102102
2. If the pull request adds functionality, the docs should be updated. Put
103103
your new functionality into a function with a docstring, and add the
104104
feature to the list in README.rst.
105-
3. The pull request should work for Python 3.4, 3.5, 3.6 and 3.7, and for PyPy. Check
105+
3. The pull request should work for Python 3.6, 3.7 and 3.8, and for PyPy. Check
106106
https://travis-ci.org/wkeeling/selenium-wire/pull_requests
107107
and make sure that the tests pass for all supported Python versions.
108108

README.rst

+2-24
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ With Selenium Wire, you author your tests in just the same way as you do with Se
1111
.. image:: https://codecov.io/gh/wkeeling/selenium-wire/branch/master/graph/badge.svg
1212
:target: https://codecov.io/gh/wkeeling/selenium-wire
1313

14-
.. image:: https://img.shields.io/badge/python-3.4%2C%203.5%2C%203.6%2C%203.7%2C%203.8-blue.svg
14+
.. image:: https://img.shields.io/badge/python-3.6%2C%203.7%2C%203.8-blue.svg
1515
:target: https://pypi.python.org/pypi/selenium-wire
1616

1717
.. image:: https://img.shields.io/pypi/v/selenium-wire.svg
@@ -68,7 +68,7 @@ Features
6868
Compatibilty
6969
~~~~~~~~~~~~
7070

71-
* Python 3.4+
71+
* Python 3.6+
7272
* Selenium 3.4.0+
7373
* Firefox, Chrome, Safari and Edge are supported
7474

@@ -744,28 +744,6 @@ The code above will print something like this to the console (loading a page wil
744744
}
745745
driver = webdriver.Firefox(seleniumwire_options=options)
746746
747-
``mitmproxy_log_level``
748-
Set the log level that the mitmproxy backend will use. The default is ``ERROR``.
749-
*Applies to the mitmproxy backend only.*
750-
751-
.. code:: python
752-
753-
options = {
754-
'mitmproxy_log_level': 'INFO' # Increase the log level to INFO for the mitmproxy backend
755-
}
756-
driver = webdriver.Firefox(seleniumwire_options=options)
757-
758-
``mitmproxy_confdir``
759-
The location of the mitmproxy configuration directory. The default is ``~/.mitmproxy``. You might want to change this if you're running in an environment where you don't have access to the user's home folder.
760-
*Applies to the mitmproxy backend only.*
761-
762-
.. code:: python
763-
764-
options = {
765-
'mitmproxy_confdir': '/tmp/.mitmproxy' # Switch the location to /tmp
766-
}
767-
driver = webdriver.Firefox(seleniumwire_options=options)
768-
769747
``port``
770748
The port number that Selenium Wire's backend listens on. You don't normally need to specify a port as a random port number is chosen automatically.
771749

requirements_dev.txt

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
pip==9.0.1
2-
bumpversion==0.5.3
3-
wheel==0.30.0
4-
watchdog==0.8.3
5-
flake8==3.5.0
6-
tox==3.16.1
7-
coverage==4.5.1
8-
Sphinx==1.7.1
9-
twine==1.10.0
1+
pip
2+
bumpversion
3+
wheel
4+
watchdog
5+
flake8
6+
tox
7+
coverage
8+
Sphinx
9+
twine
1010
nose
1111
mitmproxy

seleniumwire/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"""Top-level package for Selenium Wire."""
44

55
__author__ = """Will Keeling"""
6-
__version__ = '2.1.2'
6+
__version__ = '3.0.0'

seleniumwire/proxy/client.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,25 @@ def create_proxy(self, addr='127.0.0.1', port=0, options=None):
5353
self._capture_request_handler = CaptureRequestHandler
5454
# Set the timeout here before the handler starts executing
5555
self._capture_request_handler.timeout = options.get('connection_timeout', 5)
56-
self._proxy = ProxyHTTPServer((addr, port), self._capture_request_handler, options=options)
56+
57+
self._proxy = ProxyHTTPServer(addr, port, self._capture_request_handler, options=options)
5758

5859
t = threading.Thread(name='Selenium Wire Proxy Server', target=self._proxy.serve_forever)
5960
t.daemon = not options.get('standalone')
6061
t.start()
6162

62-
socketname = self._proxy.socket.getsockname()
63-
self._proxy_addr = socketname[0]
64-
self._proxy_port = socketname[1]
63+
self._proxy_addr, self._proxy_port = self._proxy.address()
6564
elif options.get('backend') == 'mitmproxy':
6665
# Use mitmproxy if installed
6766
from . import mitmproxy
6867

69-
self._proxy = mitmproxy.start(addr, port, options)
70-
self._proxy_addr = self._proxy.host
71-
self._proxy_port = self._proxy.port
68+
self._proxy = mitmproxy.MitmProxy(addr, port, options)
69+
70+
t = threading.Thread(name='Selenium Wire Proxy Server', target=self._proxy.serve)
71+
t.daemon = not options.get('standalone')
72+
t.start()
73+
74+
self._proxy_addr, self._proxy_port = self._proxy.address()
7275
else:
7376
raise TypeError(
7477
"Invalid backend '{}'. "

seleniumwire/proxy/handler.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ def _create_response(self, body, content_type='application/json'):
215215
def initialise(self, options):
216216
"""Perform any initialisation actions.
217217
218+
DEPRECATED
219+
218220
Args:
219221
options: The selenium wire options.
220222
"""
@@ -237,7 +239,7 @@ def capture_request(self, request):
237239
"""
238240
ignore_method = request.method in self.options.get(
239241
'ignore_http_methods', ['OPTIONS'])
240-
not_in_scope = not self._in_scope(self.scopes, request.url)
242+
not_in_scope = not self.in_scope(self.scopes, request.url)
241243
if ignore_method or not_in_scope:
242244
log.debug('Not capturing %s request: %s', request.method, request.url)
243245
return
@@ -258,7 +260,7 @@ def capture_response(self, request_id, url, response):
258260
log.info('Capturing response: %s %s %s', url, response.status_code, response.reason)
259261
self.storage.save_response(request_id, response)
260262

261-
def _in_scope(self, scopes, url):
263+
def in_scope(self, scopes, url):
262264
if not scopes:
263265
return True
264266
elif not is_list_alike(scopes):
@@ -366,10 +368,10 @@ def _create_request(self, req, req_body):
366368
@property
367369
def options(self):
368370
return self.server.options
369-
370-
@options.setter
371-
def options(self, options):
372-
self.server.options = options
371+
#
372+
# @options.setter
373+
# def options(self, options):
374+
# self.server.options = options
373375

374376
@property
375377
def scopes(self):
@@ -382,18 +384,18 @@ def scopes(self, scopes):
382384
@property
383385
def modifier(self):
384386
return self.server.modifier
385-
386-
@modifier.setter
387-
def modifier(self, modifier):
388-
self.server.modifier = modifier
387+
#
388+
# @modifier.setter
389+
# def modifier(self, modifier):
390+
# self.server.modifier = modifier
389391

390392
@property
391393
def storage(self):
392394
return self.server.storage
393-
394-
@storage.setter
395-
def storage(self, storage):
396-
self.server.storage = storage
395+
#
396+
# @storage.setter
397+
# def storage(self, storage):
398+
# self.server.storage = storage
397399

398400
@property
399401
def certdir(self):

0 commit comments

Comments
 (0)