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