அனைத்து மொழிகளும் ஃப்ரேம்வொர்க்குகளும்
Ring + reitit Clojure
/pixel.gif க்கு வரும் ரெக்வெஸ்ட்களுக்கு empty GIF மூலம் பதிலளிக்கும், Ring + reitit க்கான Clojure ஸ்னிப்பெட். 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