Scotty Haskell
一个用于 Scotty 的 Haskell 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。
Scotty Haskell
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Base64 as Base64
import qualified Data.ByteString.Lazy as BL
import Web.Scotty
-- A top-level constant: decoded once, on first use.
gif :: BL.ByteString
gif = BL.fromStrict (Base64.decodeLenient "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
main :: IO ()
main = scotty 8080 $
get "/pixel.gif" $ do
setHeader "Content-Type" "image/gif"
setHeader "Cache-Control" "no-store"
raw gif
已对照该框架当前的文档核对。
验证
curl -sI http://localhost:8080/pixel.gif