WAI + Warp Haskell
WAI + Warp ਲਈ Haskell ਸਨਿੱਪਟ, ਜੋ /pixel.gif ਦੀਆਂ ਬੇਨਤੀਆਂ ਦਾ ਜਵਾਬ ਖਾਲੀ GIF ਨਾਲ ਦਿੰਦਾ ਹੈ; GIF ਸ਼ੁਰੂਆਤ ’ਤੇ ਇੱਕ ਵਾਰ ਡੀਕੋਡ ਹੁੰਦੀ ਹੈ।
WAI + Warp Haskell
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Base64 as Base64
import qualified Data.ByteString.Lazy as BL
import Network.HTTP.Types (methodGet, status200, status404)
import Network.Wai
import Network.Wai.Handler.Warp (run)
gif :: BL.ByteString
gif = BL.fromStrict (Base64.decodeLenient "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
app :: Application
app req respond
| requestMethod req == methodGet && rawPathInfo req == "/pixel.gif" =
respond $ responseLBS status200
[("Content-Type", "image/gif"), ("Cache-Control", "no-store")] gif
| otherwise = respond $ responseLBS status404 [] "Not Found"
main :: IO ()
main = run 8080 app
ਫਰੇਮਵਰਕ ਦੇ ਮੌਜੂਦਾ ਦਸਤਾਵੇਜ਼ਾਂ ਨਾਲ ਜਾਂਚਿਆ ਗਿਆ।
ਜਾਂਚੋ
curl -sI http://localhost:8080/pixel.gif