emptygif
Wika: Filipino

Lahat ng language at framework

Rack Ruby

Isang Ruby snippet para sa Rack na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

Rack Ruby

I-install
gem install rack rackup puma
File
config.ru
Patakbuhin
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
}

Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.

Suriin

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

Opisyal na site: Rack

Iba pa sa Ruby