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 示例