emptygif
Language: English

All languages and frameworks

Rack Ruby

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

Rack Ruby

Install
gem install rack rackup puma
File
config.ru
Run
rackup -p 8080
GIF = "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==".unpack1("m0").freeze

HEADERS = {
  "content-type" => "image/gif",
  "content-length" => GIF.bytesize.to_s,
  "cache-control" => "no-store",
}.freeze

run lambda { |env|
  if env["REQUEST_METHOD"] == "GET" && env["PATH_INFO"] == "/pixel.gif"
    [200, HEADERS.dup, [GIF]]
  else
    [404, { "content-type" => "text/plain" }, ["Not Found"]]
  end
}

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Rack

More in Ruby