emptygif
زبان: فارسی

همه زبان‌ها و فریم‌ورک‌ها

Scotty Haskell

قطعه‌کد Haskell برای Scotty که به درخواست‌های /pixel.gif با GIF خالی پاسخ می‌دهد؛ 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