Dream OCaml
適用於 Dream 的 OCaml 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。
Dream OCaml
(* 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