0
我有一個全局過濾器,我想在我的基於Scalatra的API中實現。爲了簡單起見,我想要任何一個帶有一個帶有一個值欄的變量foo的API調用來引發一個403.我用一個繼承鏈開始了這個問題。如何在Scalatra過濾器中使用參數?
class NoFooBarRouter extends ScalatraServlet{
before() {
if(params.getOrElse("foo", "") == "bar") //params is empty here.
halt(403, "You are not allowed here")
else
pass()
}
}
class APIRouter extends NoFooBarRouter{
get("/someurl/:foo") {
"Hello world!"
}
}
這不起作用。在調試過程中,我注意到params變量總是空的,無論是否有參數。有沒有更好的方法,還是有另一種方法從前過濾器中提取參數?