Ring + reitit Clojure
Ring + reitit साठी Clojure स्निपेट, जो /pixel.gif वरच्या रिक्वेस्टना empty GIF ने उत्तर देतो. GIF स्टार्टअपला एकदाच डिकोड होतो.
Ring + reitit Clojure
(ns pixel.core
(:require [reitit.ring :as ring]
[ring.adapter.jetty :as jetty])
(:import (java.util Base64)))
(def gif (.decode (Base64/getDecoder) "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="))
(def app
(ring/ring-handler
(ring/router
["/pixel.gif" {:get (fn [_]
{:status 200
:headers {"Content-Type" "image/gif"
"Content-Length" (str (alength gif))
"Cache-Control" "no-store"}
:body gif})}])
(ring/create-default-handler)))
(defn -main []
(jetty/run-jetty app {:port 8080 :join? true}))
आम्ही हा स्निपेट चालवला आणि त्याने परत केलेले बाइट्स तुलना करून पाहिले.
तपासा
curl -sI http://localhost:8080/pixel.gif