HTTP(S)代理, 用于抓包调试
leveldb中, 可用于后期分析docker run --name mars -p 8888:8888 -p 9999:9999 -d ouqg/mars:1.0.0配置: /app/conf/app.toml
Go版本1.11+ 启用go module
export GO111MODULE=on启动: make run
配置支持通过环境变量覆盖, 如MARS_APP_PROXYPORT=8080
[app]
host = "0.0.0.0"
# 代理监听端口
proxyPort = 8888
# 查看流量web页监听端口
inspectorPort = 9999
[mitmProxy]
# 是否开启中间人代理,不开启则盲转发
enabled = true
# 是否解密HTTPS, 客户端系统需安装根证书
decryptHTTPS = false
# 证书缓存大小
certCacheSize = 1000
# 数据缓存大小
leveldbCacheSize = 1000$ ./mars version
Version: v1.0.0
Go Version: go1.11
Git Commit: 2151a6d
Built: 2018-11-18 20:04:17
OS/ARCH: darwin/amd64$ ./mars server -h
run proxy server
Usage:
mars server [flags]
Flags:
-c, --configFile string config file path (default "conf/app.toml")
-e, --env string dev | prod (default "prod")
-h, --help help for server经过mars的流量可在web页查看
请求包含特定header, 则转发给mars, 由mars访问实际的后端
原配置
proxy_pass http://172.16.10.103:8080;使用mars后的配置
set $targetHost $host;
if ($http_x_mars_debug = "1") {
set $targetHost "172.16.10.103:8080";
}
proxy_set_header X-Mars-Host $host;
proxy_set_header Host $targetHost;
if ($http_x_mars_debug = "1") {
proxy_pass http://127.0.0.1:8888;
break;
}原配置
[web]
type = http
local_ip = 127.0.0.1
local_port = 80
subdomain = test使用mars后的配置
[web]
type = http
local_ip = 127.0.0.1
local_port = 8888
subdomain = test
host_header_rewrite = 127.0.0.1:80实现Interceptor接口, 参考interceptor/example.go
// Interceptor 拦截器
type Interceptor interface {
// Connect 收到客户端连接, 自定义response返回
Connect(ctx *goproxy.Context, rw http.ResponseWriter)
// BeforeRequest 请求发送前, 修改request
BeforeRequest(ctx *goproxy.Context)
// BeforeResponse 响应发送前, 修改response
BeforeResponse(ctx *goproxy.Context, resp *http.Response, err error)
}默认存储为leveldb
实现Storage接口
// Storage 存取transaction接口
type Storage interface {
Get(txId string) (*Transaction, error)
Put(*Transaction) error
}内置输出到console、websocket
实现Output接口
// Output 输出transaction接口
type Output interface {
Write(*Transaction) error
}make 编译make run 编译并运行make package 生成当前平台的压缩包make package-all 生成Windows、Linux、Mac的压缩包Vue + Element UI
make install-vuemake runmake run-vuehttp://localhost:9999make build-vuego get github.com/rakyll/statikmake statik基于websocket, 消息序列化协议: json
消息格式, 请求响应相同
{
"type": 3000,
"payload": {}
}type取值范围
var ws = new WebSocket('http://localhost:9999/ws')心跳超时为30秒,连续两次超时将断开连接
请求
{
"type": 1000,
"payload": {}
}响应
{
"type": 2000,
"payload": {}
}只包含transaction基本信息
{
"type": 3000,
"payload": {
"id": "b56cb03d-855c-48a2-81e8-bbf71f285ecf",
"method": "GET",
"host": "api.zhihu.com",
"path": "/user-permission",
"duration": 235519397,
"response_status_code": 200,
"response_err": "",
"response_content_type": "application/json",
"response_len": 135
}
}请求
{
"type": 1002,
"payload": {
"id": "b56cb03d-855c-48a2-81e8-bbf71f285ecf"
}
}响应
…请求
{
"type": 1001,
"payload": {
"id": "b56cb03d-855c-48a2-81e8-bbf71f285ecf"
}
}响应
{
"type": 2001,
"payload": {
"err": ""
}
}No open issues yet, or sync has not completed.