mirror of
https://github.com/aantron/dream.git
synced 2025-12-31 00:03:52 -05:00
w-query
This very simple example accesses a value in the query string with
Dream.query:
let () =
Dream.run (fun request ->
match Dream.query "echo" request with
| None ->
Dream.respond "Use ?echo=foo to give a message to echo!"
| Some message ->
Dream.respond (Dream.html_escape message))
$ dune exec --root . ./query.exe
Visit http://localhost:8080?echo=foo and you
will see foo printed! Since we are inserting untrusted client-sent data into
an HTML response, we have to escape it with
Dream.html_escape. See
Security in example 7-template for a
discussion. Perhaps you can even launch an XSS attack against an unsafe version
of this example!