emptygif
Language: English

All languages and frameworks

Kemal Crystal

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

Kemal Crystal

Install
shards install # shard.yml: dependencies: kemal: github: kemalcr/kemal
File
src/server.cr
Run
crystal run src/server.cr
require "base64"
require "kemal"

GIF = Base64.decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

get "/pixel.gif" do |env|
  env.response.content_type = "image/gif"
  env.response.headers["Cache-Control"] = "no-store"
  env.response.write(GIF) # write the bytes; a non-String return value is ignored
  nil
end

Kemal.run(8080)

Checked against the framework's current documentation.

Check it

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

Official site: Kemal

More in Crystal