emptygif
語言: 繁體中文

所有語言和框架

WAI + Warp Haskell

適用於 WAI + Warp 的 Haskell 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。

WAI + Warp Haskell

安裝
build-depends: base, bytestring, base64-bytestring, http-types, wai, warp
檔案
Main.hs
執行
cabal run
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Base64 as Base64
import qualified Data.ByteString.Lazy as BL
import Network.HTTP.Types (methodGet, status200, status404)
import Network.Wai
import Network.Wai.Handler.Warp (run)

gif :: BL.ByteString
gif = BL.fromStrict (Base64.decodeLenient "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

app :: Application
app req respond
  | requestMethod req == methodGet && rawPathInfo req == "/pixel.gif" =
      respond $ responseLBS status200
        [("Content-Type", "image/gif"), ("Cache-Control", "no-store")] gif
  | otherwise = respond $ responseLBS status404 [] "Not Found"

main :: IO ()
main = run 8080 app

已對照該框架目前的文件確認。

驗證

curl -sI http://localhost:8080/pixel.gif

官方網站: WAI + Warp

更多 Haskell 範例