emptygif
Lingua: Italiano

Tutti i linguaggi e framework

Dream OCaml

Uno snippet OCaml per Dream che risponde alle richieste a /pixel.gif con la GIF vuota, decodificata una sola volta all'avvio.

Dream OCaml

Installa
opam install dream base64
File
pixel.ml
Esegui
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);
       ]

Verificato rispetto alla documentazione attuale del framework.

Verifica

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

Sito ufficiale: Dream