Skip to content

Commit

Permalink
unified-proxy-entry-to-extra-mock (#878)
Browse files Browse the repository at this point in the history
Co-authored-by: noO0ob <[email protected]>
  • Loading branch information
noO0oOo0ob and noO0ob authored Nov 11, 2024
1 parent 7664463 commit aa1d4b7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
12 changes: 2 additions & 10 deletions lyrebird/mitm/mitm_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def to_mock_server(flow: http.HTTPFlow):
if raw_url.port:
raw_host += f':{raw_url.port}'
# mock path 为/mock开头加上原始url
flow.request.path = '/mock/' + flow.request.url
flow.request.path = '/' + flow.request.url
# mock scheme 统一为http
flow.request.scheme = 'http'
# mock server port
Expand All @@ -43,15 +43,7 @@ def request(flow: http.HTTPFlow):
if 'mitm.it' in flow.request.url:
# Support mitm.it
return

if not PROXY_FILTERS:
to_mock_server(flow)
return

for _filter in PROXY_FILTERS:
if re.search(_filter, flow.request.url):
to_mock_server(flow)
break
to_mock_server(flow)


def responseheaders(flow):
Expand Down
3 changes: 2 additions & 1 deletion lyrebird/mitm/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def wait_for_mitm_start(self, config, logger):
def start_mitmdump(self, queue, config, logger, mitmdump_path):
proxy_port = config.get('proxy.port', 4272)
mock_port = config.get('mock.port', 9090)
extra_mock_port = config.get('extra.mock.port', 9999)
'''
--ignore_hosts:
The ignore_hosts option allows you to specify a regex which is matched against a host:port
Expand Down Expand Up @@ -79,7 +80,7 @@ def start_mitmdump(self, queue, config, logger, mitmdump_path):
if ignore_hosts:
mitm_arguments += ['--ignore-hosts', ignore_hosts]
mitmenv = os.environ
mitmenv['PROXY_PORT'] = str(mock_port)
mitmenv['PROXY_PORT'] = str(extra_mock_port)
mitmenv['PROXY_FILTERS'] = json.dumps(config.get('proxy.filters', []))
logger.info('HTTP proxy server starting...')
subprocess.Popen([str(mitmdump_path)]+mitm_arguments, env=mitmenv)
Expand Down

0 comments on commit aa1d4b7

Please sign in to comment.