2012-08-23 68 views
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-3比例,APP_KEY = req.http.x-appid

但是我不能得到這個工作!我失去了一些東西

回答

0

你可以嘗試這樣的

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

在客戶端,你應該以明文

設置SomeOtherHeader東西來使用來自VMOD header獲得方法,但你爲什麼不設置這個X- 3scale-app_id直接在客戶端?

+0

它通過3scale通過api認證。我會嘗試vmod標題。請求應該如何看待客戶端?大概是 –

+0

setRequestHeader – ghloogh