21 lines
680 B
Python
21 lines
680 B
Python
from mitmproxy import http
|
|
import redis, json, base64
|
|
r = redis.Redis('192.168.12.2')
|
|
|
|
def response(flow: http.HTTPFlow) -> None:
|
|
# if not flow.request.url.endswith('.webp'):
|
|
# return
|
|
if not (200 <= flow.response.status_code < 300):
|
|
return
|
|
|
|
response_data = {
|
|
"status_code": flow.response.status_code,
|
|
"headers": dict(flow.response.headers),
|
|
"content": base64.b64encode(flow.response.content).decode('utf-8')
|
|
}
|
|
# JSON 문자열로 변환
|
|
response_json = json.dumps(response_data)
|
|
|
|
# Redis에 저장
|
|
r.hset('static', flow.request.url, response_json)
|
|
print(f"Cached response for {flow.request.url}") |