]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/ocaml-http/examples/basic_auth.ml
http basic authentication example
[helm.git] / helm / DEVEL / ocaml-http / examples / basic_auth.ml
diff --git a/helm/DEVEL/ocaml-http/examples/basic_auth.ml b/helm/DEVEL/ocaml-http/examples/basic_auth.ml
new file mode 100644 (file)
index 0000000..f9d75a7
--- /dev/null
@@ -0,0 +1,10 @@
+
+let callback (req: Http_types.request) outchan =
+  match req#authorization with
+  | Some (`Basic (username, password))
+    when username = "foo" && password = "bar" ->
+      Http_daemon.respond ~code:200 ~body:"secret page!" outchan
+  | _ -> raise (Http_types.Unauthorized "my secret site")
+
+let _ = Http_daemon.start' ~port:9999 callback
+