这里是 Haskell 新手!
在我的 haskell 项目中,我使用 scotty 来提供一些动态生成的 html 页面。问题在于,由于“x-frame-options” header 设置为“SAMEORIGIN”,因此无法在 iframe 内打开页面。
如何将该标题更改为不同的内容?我想为所有响应设置该 header 。有没有中间件可以做到这一点?
谢谢!
最佳答案
您可以定义自己的中间件,将此 header 添加到每个响应中(所有必需的工具都可以在 Network.Wai
中找到):
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai -- from the wai package
import Web.Scotty hiding (options)
addFrameHeader :: Middleware
addFrameHeader =
modifyResponse (mapResponseHeaders (("X-Frame-Options", "whatever") :))
然后在你的 scotty 应用程序中使用它:
main = scotty 6000 $ do
middleware addFrameHeader
get "/" (text "hello")
通过 curl
我们可以看到它包含在响应中:
> curl --include localhost:6000
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Thu, 19 Jan 2017 19:22:57 GMT
Server: Warp/3.2.8
X-Frame-Options: whatever
Content-Type: text/plain; charset=utf-8
hello
关于 haskell -斯科蒂 : Set custom headers (x-frame-options),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41720611/