python - 拦截标头并即时修改
问题描述
我的任务是开发一个 mitmproxy 脚本,这是我以前从未做过的事情。
我正在尝试在 mitmproxy 中的反向代理实例上的 http-flow 期间动态修改“位置”标头,这些标头通常不同,但我现在的主要目标是简单地以静态方式检测它们。
我正在运行 mitmproxy:
mitmdump --set flowdetail:3 -s rproxy.py -p 8080 --mode reverse:http://www.com
^ 当然,这不是问题的真实 URL。
假设我有从服务器位置发送的标头:http: //www.com/example-location
但我想将其更改为 Location: http://localhost:8080/example-location
我已经尝试了可以在 google 上找到的所有示例,包括 StackOverFlow 上的示例。有些事情我尝试过但没有成功。
from mitmproxy import http
import sys
def response(flow: http.HTTPFlow) -> None:
flow.request.host = "http://localhost:8080/example-location"
from mitmproxy import http
import sys
def response(flow):
flow.repsonse.headers['Location'] = ["http://localhost:8080/example-location"]
flow.repsonse.headers['Location'] = "http://localhost:8080/example-location" ## I tried this line separately without the above line
和
from mitmproxy import http
import sys
def response(flow: http.HTTPFlow) -> None:
flow.repsonse.headers['Location'] = ["http://localhost:8080/example-location"]
flow.repsonse.headers['Location'] = "http://localhost:8080/example-location" ## I tried this line separately without the above line
我该如何正确地做到这一点?
如果无法操纵此标头(但为什么不应该),我有什么选择?
解决方案
推荐阅读
- vb.net - 如何在 vb.net 中一段时间后出现消息框?
- java - 将地图转换为嵌套地图
- php - PHP在类声明中从A获取B类静态属性
- powershell - 使用 Powershell 更新 Active Directory 用户电子邮件
- jdbc - 通过 Windows 身份验证的数据库连接
- laravel - 带有 nuxtjs 的 laravel 护照
- java - 如何定位字符串的特定部分,即该子字符串左侧的 (x) 个字符?(爪哇)
- javascript - Jquery - 在复选框单击时按类查找最接近的前一个。复选框在里面
- typescript - 将具有可为空字符串属性的接口转换为字符串属性
- x86 - x86 UEFI 引导:UEFI 真的需要从地址 0 开始的传统 1MiB 填充吗?