1

我正在使用 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

但是我不能让它工作!我错过了一些东西

4

1 回答 1

0

您可以尝试使用来自 vmod标头的 get 方法,如下所示

set req.X-3scale-app_id = header.get(req.http.SomeOtherHeader,".*");

在客户端,您应该以纯文本设置 SomeOtherHeader

但是为什么不直接在客户端设置这个 X-3scale-app_id 呢?

于 2012-08-23T15:43:03.987 回答