emptygif
語言: 繁體中文

所有語言和框架

Kemal Crystal

適用於 Kemal 的 Crystal 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。

Kemal Crystal

安裝
shards install # shard.yml: dependencies: kemal: github: kemalcr/kemal
檔案
src/server.cr
執行
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)

已對照該框架目前的文件確認。

驗證

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

官方網站: Kemal

更多 Crystal 範例