emptygif
Langue: Français

Tous les langages et frameworks

Scotty Haskell

Un extrait Haskell pour Scotty qui répond aux requêtes sur /pixel.gif avec le GIF vide, décodé une seule fois au démarrage.

Scotty Haskell

Installer
build-depends: base, bytestring, base64-bytestring, scotty
Fichier
Main.hs
Lancer
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

Vérifié par rapport à la documentation actuelle du framework.

Vérifier

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

Site officiel: Scotty

Autres extraits en Haskell