Roda Ruby
適用於 Roda 的 Ruby 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。
Roda Ruby
require "roda"
class App < Roda
GIF = "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==".unpack1("m0").freeze
route do |r|
# Roda string matchers are written without the leading slash.
r.get "/pixel.gif".delete_prefix("/") do
response["content-type"] = "image/gif"
response["cache-control"] = "no-store"
GIF
end
end
end
run App.freeze.app
我們執行了這段程式碼,並比對了它回傳的位元組。
驗證
curl -sI http://localhost:8080/pixel.gif