அனைத்து மொழிகளும் ஃப்ரேம்வொர்க்குகளும்
Hanami Ruby
/pixel.gif க்கு வரும் ரெக்வெஸ்ட்களுக்கு empty GIF மூலம் பதிலளிக்கும், Hanami க்கான Ruby ஸ்னிப்பெட். GIF ஸ்டார்ட்அப்பில் ஒருமுறை மட்டுமே டீகோட் செய்யப்படுகிறது.
Hanami Ruby
# app/actions/pixel/show.rb
module MyApp
module Actions
module Pixel
class Show < MyApp::Action
GIF = "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==".unpack1("m0").freeze
def handle(request, response)
# Rack's content_type= sets the exact header; format= would append "; charset=utf-8".
response.content_type = "image/gif"
response.headers["Cache-Control"] = "no-store"
response.body = GIF
end
end
end
end
end
# config/routes.rb
module MyApp
class Routes < Hanami::Routes
get "/pixel.gif", to: "pixel.show"
end
end
இந்த ஸ்னிப்பெட்டை ரன் செய்து, அது திருப்பித் தந்த பைட்களை ஒப்பிட்டுப் பார்த்தோம்.
சரிபார்
curl -sI http://localhost:8080/pixel.gif