emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Kemal Crystal

Snippet Crystal untuk Kemal yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

Kemal Crystal

Instal
shards install # shard.yml: dependencies: kemal: github: kemalcr/kemal
File
src/server.cr
Jalankan
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)

Dicek terhadap dokumentasi terbaru framework tersebut.

Periksa

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

Situs resmi: Kemal

Lainnya dalam Crystal