emptygif
言語: 日本語

すべての言語・フレームワーク

Roda Ruby

/pixel.gif へのリクエストに空の GIF を返す、Roda 用の Ruby スニペット。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 の他の例