之前总在想像 http、https 的 get 等接口都是直接可以调用的,能直接生成用例就好了
最近接触到 Nginx,于是了解了一下流量复制,学习了 lua 脚本
通过 nginx 正向代理,对流量数据进行复制,
对指定的请求解析过滤,
将解析的结果丢到 spring 服务进行保存
server {
listen 7000;
location / {
mirror /mirror;
resolver 8.8.8.8;
proxy_pass $scheme://$http_host$request_uri;
}
location /mirror {
proxy_pass http://127.0.0.1:7001/;
}
}
local cjson = require("cjson")
local log_json = {}
log_json["headers"] = ngx.req.get_headers()
log_json["uri_args"] = ngx.req.get_uri_args()
log_json["body"] = ngx.req.read_body()
log_json["http_version"] = ngx.req.http_version()
log_json["method"] =ngx.req.get_method()
log_json["body_data"] = ngx.req.get_body_data()
local message = cjson.encode(log_json);
local http = require "resty.http"
local httpc = http.new()
local resp, err = httpc:request_uri(
"http://127.0.0.1:9980/本地spring服务地址",
{
method="POST",
body=messag,
headers = {
["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36"
}
}
)
brew install erlang elixir openssl expat libyaml libiconv libgd sqlite rebar rebar3 automake autoconf
export LDFLAGS="-L/usr/local/opt/openssl/lib -L/usr/local/lib -L/usr/local/opt/expat/lib"
export CFLAGS="-I/usr/local/opt/openssl/include/ -I/usr/local/include -I/usr/local/opt/expat/include"
export CPPFLAGS="-I/usr/local/opt/openssl/include/ -I/usr/local/include -I/usr/local/opt/expat/include"
brew install openresty