emptygif
Language: English

All languages and frameworks

Roda Ruby

A Ruby snippet for Roda that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Roda Ruby

Install
gem install roda rackup puma
File
config.ru
Run
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

We ran this snippet and compared the bytes it returned.

Check it

curl -sI http://localhost:8080/pixel.gif

Official site: Roda

More in Ruby