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

Commit 9efa17b

Browse files
committed
Fix existing unit tests
1 parent 778b835 commit 9efa17b

File tree

13 files changed

+58
-513
lines changed

13 files changed

+58
-513
lines changed

.editorconfig

-21
This file was deleted.

MANIFEST.in

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ include README.rst
88
recursive-include tests *
99
recursive-include seleniumwire *.crt
1010
recursive-include seleniumwire *.key
11-
recursive-include seleniumwire *.exe
1211
recursive-include seleniumwire *.cnf
1312
recursive-exclude * __pycache__
1413
recursive-exclude * *.py[co]

Makefile

-88
This file was deleted.

seleniumwire/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import signal
44
from argparse import RawDescriptionHelpFormatter
55

6-
from seleniumwire.thirdparty.mitmproxy import backend, utils
6+
from seleniumwire import backend, utils
77

88
logging.basicConfig(level=logging.DEBUG, format='%(message)s')
99

seleniumwire/server.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
import logging
33

44
from seleniumwire.handler import MitmProxyRequestHandler
5+
from seleniumwire.modifier import RequestModifier
6+
from seleniumwire.storage import RequestStorage
57
from seleniumwire.thirdparty.mitmproxy import addons
6-
from seleniumwire.thirdparty.mitmproxy.exceptions import Timeout
78
from seleniumwire.thirdparty.mitmproxy.master import Master
89
from seleniumwire.thirdparty.mitmproxy.options import Options
910
from seleniumwire.thirdparty.mitmproxy.server import ProxyConfig, ProxyServer
10-
from seleniumwire.modifier import RequestModifier
11-
from seleniumwire.storage import RequestStorage
1211
from seleniumwire.utils import extract_cert_and_key, get_upstream_proxy
1312

1413
logger = logging.getLogger(__name__)
@@ -27,7 +26,7 @@ def __init__(self, host, port, options):
2726
self.storage = RequestStorage(
2827
base_dir=options.pop('request_storage_base_dir', None)
2928
)
30-
extract_cert_and_key(self.storage.storage_home)
29+
extract_cert_and_key(self.storage.home_dir)
3130

3231
# Used to modify requests/responses passing through the server
3332
# DEPRECATED. Will be superceded by request/response interceptors.
@@ -49,7 +48,7 @@ def __init__(self, host, port, options):
4948

5049
# mitmproxy specific options
5150
mitmproxy_opts = Options(
52-
confdir=self.storage.storage_home,
51+
confdir=self.storage.home_dir,
5352
listen_host=host,
5453
listen_port=port,
5554
)

seleniumwire/storage.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ def __init__(self, base_dir=None):
3737
if base_dir is None:
3838
base_dir = os.path.expanduser('~')
3939

40-
self.storage_home = os.path.join(base_dir, '.seleniumwire')
41-
self.storage_session = os.path.join(self.storage_home, 'storage-{}'.format(str(uuid.uuid4())))
42-
os.makedirs(self.storage_session, exist_ok=True)
40+
""""""
41+
self.home_dir = os.path.join(base_dir, '.seleniumwire')
42+
self.session_dir = os.path.join(self.home_dir, 'storage-{}'.format(str(uuid.uuid4())))
43+
os.makedirs(self.session_dir, exist_ok=True)
4344
self._cleanup_old_dirs()
4445

4546
# Index of requests received.
@@ -73,7 +74,7 @@ def _index_request(self, request):
7374
return request_id
7475

7576
def _save(self, obj, dirname, filename):
76-
request_dir = os.path.join(self.storage_session, dirname)
77+
request_dir = os.path.join(self.session_dir, dirname)
7778

7879
with open(os.path.join(request_dir, filename), 'wb') as out:
7980
pickle.dump(obj, out)
@@ -217,19 +218,19 @@ def find(self, path, check_response=True):
217218
return None
218219

219220
def _get_request_dir(self, request_id):
220-
return os.path.join(self.storage_session, 'request-{}'.format(request_id))
221+
return os.path.join(self.session_dir, 'request-{}'.format(request_id))
221222

222223
def cleanup(self):
223224
"""Removes all stored requests, the storage directory containing those
224225
requests, and if that is the only storage directory, also removes the
225226
top level parent directory.
226227
"""
227-
log.debug('Cleaning up %s', self.storage_session)
228+
log.debug('Cleaning up %s', self.session_dir)
228229
self.clear_requests()
229-
shutil.rmtree(self.storage_session, ignore_errors=True)
230+
shutil.rmtree(self.session_dir, ignore_errors=True)
230231
try:
231232
# Attempt to remove the parent folder if it is empty
232-
os.rmdir(os.path.dirname(self.storage_session))
233+
os.rmdir(os.path.dirname(self.session_dir))
233234
except OSError:
234235
# Parent folder not empty
235236
pass
@@ -238,7 +239,7 @@ def _cleanup_old_dirs(self):
238239
"""Cleans up and removes any old storage directories that were not previously
239240
cleaned up properly by _cleanup().
240241
"""
241-
parent_dir = os.path.dirname(self.storage_session)
242+
parent_dir = os.path.dirname(self.session_dir)
242243
for storage_dir in os.listdir(parent_dir):
243244
storage_dir = os.path.join(parent_dir, storage_dir)
244245
try:

seleniumwire/thirdparty/mitmproxy/net/http/http1/read.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import typing
55

66
from seleniumwire.thirdparty.mitmproxy import exceptions
7-
from seleniumwire.thirdparty.mitmproxy.net.http import headers, request, response, url
7+
from seleniumwire.thirdparty.mitmproxy.net.http import (headers, request,
8+
response, url)
89

910

1011
def get_header_tokens(headers, key):
@@ -255,6 +256,12 @@ def _read_request_line(rfile):
255256
raise ValueError
256257
else:
257258
scheme, rest = target.split(b"://", maxsplit=1)
259+
# There seems to be a bug here for http URLs that
260+
# have no path and don't end with a slash - e.g.
261+
# http://python.org
262+
# Add a slash in this case.
263+
if not rest.endswith(b"/"):
264+
rest = rest + b"/"
258265
authority, path_ = rest.split(b"/", maxsplit=1)
259266
path = b"/" + path_
260267
host, port = url.parse_authority(authority, check=True)

0 commit comments

Comments
 (0)