emptygif
Language: English

All languages and frameworks

Scotty Haskell

A Haskell snippet for Scotty that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Scotty Haskell

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

Checked against the framework's current documentation.

Check it

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

Official site: Scotty

More in Haskell