emptygif
اللغة: العربية

كل اللغات وأطر العمل

Dream OCaml

مقتطف بلغة OCaml لـ Dream يستجيب لطلبات /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