diff --git a/examples/echo.ml b/examples/echo.ml index 1b5e4a42..bc1607e7 100644 --- a/examples/echo.ml +++ b/examples/echo.ml @@ -116,16 +116,23 @@ let () = (* main page *) S.add_route_handler server S.Route.(return) (fun _req -> - let s = "\n\ -

welcome!\n

endpoints are:\n

" - in + let open Tiny_httpd_html in + let h = html [] [ + head[][title[][txt "index of echo"]]; + body[][ + h3[] [txt "welcome!"]; + p[] [b[] [txt "endpoints are:"]]; + ul[] [ + li[][pre[][txt "/hello/:name (GET)"]]; + li[][pre[][a[A.href "/echo/"][txt "echo"]; txt " echo back query"]]; + li[][pre[][txt "/upload/:path (PUT) to upload a file"]]; + li[][pre[][txt "/zcat/:path (GET) to download a file (deflate transfer-encoding)"]]; + li[][pre[][a[A.href "/stats/"][txt"/stats/"]; txt" (GET) to access statistics"]]; + li[][pre[][a[A.href "/vfs/"][txt"/vfs"]; txt" (GET) to access a VFS embedded in the binary"]]; + ] + ] + ] in + let s = to_string_top h in S.Response.make_string ~headers:["content-type", "text/html"] @@ Ok s); Printf.printf "listening on http://%s:%d\n%!" (S.addr server) (S.port server); diff --git a/tests/dune b/tests/dune index 163eaf86..53bf6ea5 100644 --- a/tests/dune +++ b/tests/dune @@ -57,7 +57,6 @@ (enabled_if (= %{system} "linux")) (action (diff dl-out.expect dl-out))) - (rule (targets foo_50) (enabled_if (= %{system} "linux")) diff --git a/tests/echo1.expect b/tests/echo1.expect index 541334f7..65ab6c65 100644 --- a/tests/echo1.expect +++ b/tests/echo1.expect @@ -7,3 +7,65 @@ echo: path="/echo/?a=b&c=d"; body=""; path_components=["echo"]; query=["c","d";"a","b"]} (query: "c" = "d";"a" = "b") + + + + +list directory "Embedded_fs" + + + + + +

+Index of "" +

+ + + +hello +world + + + + + + +

funky:

+ + + + diff --git a/tests/echo1.sh b/tests/echo1.sh index 22398c94..90f7d204 100755 --- a/tests/echo1.sh +++ b/tests/echo1.sh @@ -7,4 +7,14 @@ PORT=8085 PID=$! sleep 0.1 curl -N "http://localhost:${PORT}/echo/?a=b&c=d" -H user-agent:test + +sleep 0.1 +curl -N "http://localhost:${PORT}/vfs/" + +sleep 0.1 +curl -N "http://localhost:${PORT}/vfs/a.txt" + +sleep 0.1 +curl -N "http://localhost:${PORT}/vfs/sub/yolo.html" + kill $PID diff --git a/tests/html/makehtml.ml b/tests/html/makehtml.ml index 7d0ef3c8..fcf7e313 100644 --- a/tests/html/makehtml.ml +++ b/tests/html/makehtml.ml @@ -6,6 +6,7 @@ let t1() = head [] []; body [] [ ul [A.style "list-style: circle"] ( + li[][pre [] [txt "a"; txt "b"]] :: List.init 100 (fun i -> li [A.id (spf "l%d" i)] [txt (spf "item %d" i)]) ) ] @@ -15,10 +16,11 @@ let t1() = let t2() = html [] [ head [] []; + pre [] [txt "a"; txt "b"]; body [] [ - ul' [A.style "list-style: circle"] (fun buf -> + ul' [A.style "list-style: circle"] (fun out -> for i=0 to 99 do - li ~if_:(i<> 42) [A.id (spf "l%d" i)] [txt (spf "item %d" i)] buf + li ~if_:(i<> 42) [A.id (spf "l%d" i)] [txt (spf "item %d" i)] out done ) ] diff --git a/tests/html/t1.expected.html b/tests/html/t1.expected.html index dd0eb3a8..9ac5658c 100644 --- a/tests/html/t1.expected.html +++ b/tests/html/t1.expected.html @@ -5,6 +5,10 @@