emptygif
언어: 한국어

모든 언어 및 프레임워크

WAI + Warp Haskell

/pixel.gif 요청에 빈 GIF로 응답하는 WAI + Warp용 Haskell 스니펫입니다. 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의 다른 예제