emptygif
語言: 繁體中文

所有語言和框架

Roda Ruby

適用於 Roda 的 Ruby 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。

Roda Ruby

安裝
gem install roda rackup puma
檔案
config.ru
執行
rackup -p 8080
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

官方網站: Roda

更多 Ruby 範例