emptygif
언어: 한국어

모든 언어 및 프레임워크

Scotty Haskell

/pixel.gif 요청에 빈 GIF로 응답하는 Scotty용 Haskell 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.

Scotty Haskell

설치
build-depends: base, bytestring, base64-bytestring, scotty
파일
Main.hs
실행
cabal run
{-# 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

공식 사이트: Scotty

Haskell의 다른 예제