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 示例