Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Unified agent entry to extra mock #878

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading