emptygif
Ngôn ngữ: Tiếng Việt

Tất cả ngôn ngữ và framework

Dream OCaml

Đoạn mã OCaml cho Dream, trả lời các yêu cầu tới /pixel.gif bằng GIF rỗng, được giải mã một lần khi khởi động.

Dream OCaml

Cài đặt
opam install dream base64
Tệp
pixel.ml
Chạy
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);
       ]

Đã đối chiếu với tài liệu hiện hành của framework.

Kiểm tra

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

Trang chính thức: Dream