gpt4 book ai didi

scala - 提起过滤器以强制 ssl

转载 作者:行者123 更新时间:2023-12-02 06:12:56 25 4
gpt4 key购买 nike

在 struts 应用程序中,我有一个过滤器,强制只能通过重定向通过 https 访问某些页面。我正在考虑将其移植为 lift,所以我的问题是:在这种环境中,是否有一种“lift”方式来实现此类过滤器,或者它与 struts 中的类似/相同吗?谢谢

最佳答案

在 Lift 中,SiteMap 定义了页面访问的规则。您可以创建一个 SiteMap 条目,在某些页面上重定向到 https 站点:

// create an object that does a redirect to the https server if the
// request is on http
object RequireSSL extends Loc.EarlyResponse(
() => {
for {
r <- S.request
lowLevelReq <- Box !! r if lowLevelReq.scheme == "http"
} {
S.redirectTo("https://"+lowLevelReq.serverName+lowLevelReq.contextPath)
}
Empty
})

// Build SiteMap
def entries = (Menu("Home") / "index") ::
(Menu("Secure") / "secure" >> RequireSSL) ::
Nil

希望这有帮助。

关于scala - 提起过滤器以强制 ssl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3134454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com