emptygif
語言: 繁體中文

所有語言和框架

Dream OCaml

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

Dream OCaml

安裝
opam install dream base64
檔案
pixel.ml
執行
dune exec ./pixel.exe
(* dune: (executable (name pixel) (libraries dream base64)) *)
let gif = Base64.decode_exn "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="

let () =
  Dream.run ~interface:"0.0.0.0" ~port:8080
  @@ Dream.logger
  @@ Dream.router
       [
         Dream.get "/pixel.gif" (fun _ ->
             Dream.respond
               ~headers:[ ("Content-Type", "image/gif"); ("Cache-Control", "no-store") ]
               gif);
       ]

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

驗證

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

官方網站: Dream