- let code =
- match status with
- | None -> code
- | Some (s: Http_types.redirection_status) -> code_of_status s
- in
- send_empty_response
- "Daemon.respond_redirect" ~is_valid_status:is_redirection
- ~headers:["Location", location] ~body ()
- ~version ~code outchan
-
-let respond_error
- ?(body = "") ?(version = http_version) ?(code = 400) ?status outchan =
- let code =
- match status with
- | None -> code
- | Some s -> code_of_status s
- in
- send_empty_response
- "Daemon.respond_error" ~is_valid_status:is_error ~body ()
- ~version ~code outchan
-
-let respond_not_found ~url ?(version = http_version) outchan =
- send_empty_response
- "Daemon.respond_not_found" ~body:"" () ~version ~code:404 outchan
-
-let respond_forbidden ~url ?(version = http_version) outchan =
- send_empty_response
- "Daemon.respond_permission_denied" ~body:"" () ~version ~code:403 outchan
-
-(* let send_file ?name ?file outchan = *)
+ send_empty_response "Daemon.respond_redirect" ~is_valid_status:is_redirection
+ ~headers:["Location", location] ?body () ?version code outchan
+
+let respond_error ?body ?version ?(code = `Code 400) outchan =
+ send_empty_response "Daemon.respond_error" ~is_valid_status:is_error
+ ?body () ?version code outchan
+
+let respond_not_found ~url ?version outchan =
+ send_empty_response "Daemon.respond_not_found" () ?version (`Code 404) outchan
+
+let respond_forbidden ~url ?version outchan =
+ send_empty_response "Daemon.respond_permission_denied" () ?version
+ (`Code 403) outchan
+
+let respond_unauthorized ?version ?(realm = server_string) outchan =
+ respond ~headers:["WWW-Authenticate", sprintf "Basic realm=\"%s\"" realm]
+ ~code:(`Code 401) outchan
+