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

DRAFT: automated QA experiments #8177

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
52 changes: 52 additions & 0 deletions scripts/mitmproxy_parsing_request_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from mitmproxy.net.http.http1.assemble import assemble_request, assemble_response
from datetime import datetime
import math
from urllib.parse import urlsplit

# Use a context manager to handle file operations
f = open('./output.txt', 'w')

def response(flow):
# Convert timestamps to milliseconds
req_ts = math.floor(flow.request.timestamp_start * 1000)
req_te = math.floor(flow.request.timestamp_end * 1000)
resp_ts = math.floor(flow.response.timestamp_start * 1000)
resp_te = math.floor(flow.response.timestamp_end * 1000)

# Calculate total times
request_total_time = req_te - req_ts
response_total_time = resp_te - resp_ts
total_time = resp_te - req_ts

# Convert timestamps to human-readable dates
req_ts_human = datetime.fromtimestamp(req_ts / 1000).strftime('%Y-%m-%d %H:%M:%S.%f')
req_te_human = datetime.fromtimestamp(req_te / 1000).strftime('%Y-%m-%d %H:%M:%S.%f')
resp_ts_human = datetime.fromtimestamp(resp_ts / 1000).strftime('%Y-%m-%d %H:%M:%S.%f')
resp_te_human = datetime.fromtimestamp(resp_te / 1000).strftime('%Y-%m-%d %H:%M:%S.%f')

# Parse the URL to separate path and query string
url_parts = urlsplit(flow.request.path)
path = url_parts.path
query = url_parts.query

# Format data as a comma-separated string
data = (
f"{req_ts_human},"
f"{req_te_human},"
f"{request_total_time},"
f"{flow.request.method},"
f"{flow.request.host},"
f"{path},"
f"{query},"
f"{flow.response.status_code},"
f"{resp_ts_human},"
f"{resp_te_human},"
f"{response_total_time},"
f"{total_time}\n"
)

# need to figure out how to get the content-length header
# f"{flow.response.headers['Content-Length']}\n"

# Write the formatted string to the file
f.write(data)
Loading