【goreplay】python简单使用goreplay中间件功能
一、场景
流量录制,需要对播放的流量进程定制化处理,那么可以使用中间件来实现
二、官网
https://pypi.org/project/gor/
三、编写中间件代码
# coding: utf-8 import sys from gor.middleware import AsyncioGor def on_request(proxy, msg, **kwargs): proxy.on('response', on_response, idx=msg.id, req=msg) def on_response(proxy, msg, **kwargs): proxy.on('replay', on_replay, idx=kwargs['req'].id, req=kwargs['req'], resp=msg) def on_replay(proxy, msg, **kwargs): replay_status = proxy.http_status(msg.http) resp_status = proxy.http_status(kwargs['resp'].http) if replay_status != resp_status: sys.stderr.write('replay status [%s] diffs from response status [%s]\n' % (replay_status, resp_status)) else: sys.stderr.write('replay status is same as response status\n') sys.stderr.flush() if __name__ == '__main__': proxy = AsyncioGor() proxy.on('request', on_request) proxy.run()
有on_request, on_response, on_replay三个关键方法
四、使用
sudo ./gor --input-raw :8000 --middleware "python3 /path/to/middleware.py" --output-http-track-response --input-raw-track-response --output-http="http://192.168.3.123:8001"
可能会报错
需要使用sudo安装gor库
$ sudo pip3 install gor Collecting gor Downloading gor-0.2.3-py3-none-any.whl (6.9 kB) Installing collected packages: gor Successfully installed gor-0.2.3
五、我们查看效果
参考链接:
https://pypi.org/project/gor/
分类:
Python-Basic
, Software Test
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?