WAI + Warp Haskell
/pixel.gif 요청에 빈 GIF로 응답하는 WAI + Warp용 Haskell 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.
WAI + Warp Haskell
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Base64 as Base64
import qualified Data.ByteString.Char8 as BC
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"),
("Content-Length", BC.pack (show (BL.length 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