emptygif
언어: 한국어

모든 언어 및 프레임워크

Dream OCaml

/pixel.gif 요청에 빈 GIF로 응답하는 Dream용 OCaml 스니펫입니다. 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