Echo handler for debugging

This commit is contained in:
Anton Bachin 2021-03-24 10:47:39 +03:00
parent a30edb3a81
commit 0074b391bc
9 changed files with 37 additions and 0 deletions

6
example/w-echo/Makefile Normal file
View File

@ -0,0 +1,6 @@
.PHONY : run
run :
@tput rmam || true
@stty -echo || true
@dune exec --no-print-directory -- ./echo.exe
@tput smam || true

1
example/w-echo/README.md Normal file
View File

@ -0,0 +1 @@
<!-- TODO -->

3
example/w-echo/dune Normal file
View File

@ -0,0 +1,3 @@
(executable
(name echo)
(libraries dream))

View File

@ -0,0 +1 @@
(lang dune 2.0)

2
example/w-echo/echo.ml Normal file
View File

@ -0,0 +1,2 @@
let () =
Dream.run (Dream.logger Dream.echo)

7
example/w-echo/echo.opam Normal file
View File

@ -0,0 +1,7 @@
opam-version: "2.0"
depends: [
"dream"
"dune" {>= "2.0.0"}
"ocaml"
]

View File

@ -14,6 +14,7 @@ end
include Dream__pure.Inmost
include Dream__middleware.Log
include Dream__middleware.Echo
let logger =
Dream__middleware.Log.logger

View File

@ -747,6 +747,8 @@ val logger : middleware
next handler has returned a response. Time spent logging is included in the
timings. *)
val echo : handler
(** {1 Routing} *)

14
src/middleware/echo.ml Normal file
View File

@ -0,0 +1,14 @@
(* This file is part of Dream, released under the MIT license. See
LICENSE.md for details, or visit https://github.com/aantron/dream.
Copyright 2021 Anton Bachin *)
module Dream = Dream__pure.Inmost
(* TODO Convert to streaming later. *)
let echo request =
Lwt.map Dream.response (Dream.body request)