emptygif
Language: English

All languages and frameworks

Dream OCaml

A OCaml snippet for Dream that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Dream OCaml

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

Checked against the framework's current documentation.

Check it

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

Official site: Dream