emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Scotty Haskell

Snippet Haskell untuk Scotty yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

Scotty Haskell

Instal
build-depends: base, bytestring, base64-bytestring, scotty
File
Main.hs
Jalankan
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

Dicek terhadap dokumentasi terbaru framework tersebut.

Periksa

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

Situs resmi: Scotty

Lainnya dalam Haskell