我使用3scale来管理任何API的前端。我想在请求的标题中包含API而不是URL字符串(似乎有点整洁)
此刻它被定义为。
set req.http.X-3scale-app_id = regsub(req.url,".*[&?](app_id.[^&]*).*","\1");
set req.http.X-3scale-app_key = regsub(req.url,".*[&?](app_key.[^&]*).*","\1");
set req.http.X-3scale-user_key = regsub(req.url,".*[&?](user_key.[^&]*).*","\1");
set req.http.X-3scale-user_id = regsub(req.url,".*[&?](user_id.[^&]*).*","\1");
if (req.http.X-3scale-app_id != req.url) {
set req.http.X-3scale-authrep = req.http.X-3scale-authrep + "&" + req.http.X-3scale-app_id;
}
if (req.http.X-3scale-app_key != req.url ) {
set req.http.X-3scale-authrep = req.http.X-3scale-authrep + "&" + req.http.X-3scale-app_key;
}
if (req.http.X-3scale-user_id != req.url) {
set req.http.X-3scale-authrep = req.http.X-3scale-authrep + "&" + req.http.X-3scale-user_id;
}
if (req.http.X-3scale-user_key != req.url) {
set req.http.X-3scale-authrep = req.http.X-3scale-authrep + "&" + req.http.X-3scale-user_key;
}
unset req.http.X-3scale-app_id;
unset req.http.X-3scale-app_key;
unset req.http.X-3scale-user_id;
unset req.http.X-3scale-user_key;
我想做的是从标题中取出键,因为我觉得它看起来更好,所以我可以做类似......
设置req.http.X-3scale-app_key = req.http.x-appid
然而,我不能让这个工作!我错过了什么
答案 0 :(得分:0)
您可以尝试使用vmod header中的get方法使用类似
的方法set req.X-3scale-app_id = header.get(req.http.SomeOtherHeader,".*");
在客户端,您应该以明文
设置SomeOtherHeader但是为什么你不直接在客户端设置这个X-3scale-app_id?