open Printf
open Http_getter_common
+open Http_getter_const
open Http_getter_misc
open Http_getter_types
| "backward" -> `Backward
| c -> raise (Bad_request ("Invalid RDF class: " ^ c))
+let html_tag ?exn () =
+ let xml_decl = "<?xml version=\"1.0\"?>\n" in
+ match exn with
+ | Some (exn, value) ->
+ sprintf
+ "%s<html xmlns=\"%s\"\nxmlns:helm=\"%s\"\nhelm:exception=\"%s\"\nhelm:exception_arg=\"%s\">\n"
+ xml_decl xhtml_ns helm_ns exn value
+ | None ->
+ sprintf "%s<html xmlns=\"%s\"\nxmlns:helm=\"%s\">\n"
+ xml_decl xhtml_ns helm_ns
+
let mk_return_fun pp_fun contype msg outchan =
Http_daemon.respond
~body:(pp_fun msg) ~headers:["Content-Type", contype] outchan
-let pp_error s =
- sprintf "<html><body>Http Getter error: <span style=\"color:red\">%s</span></body></html>" s
-let pp_internal_error s =
- sprintf "<html><body>Http Getter Internal error: <span style=\"color:red\">%s</span></body></html>" s
-let pp_msg s = sprintf "<html><body>%s</body></html>" s
+let pp_msg s = sprintf "%s<body>%s</body></html>" (html_tag ()) s
let null_pp s = s
-let return_html_error = mk_return_fun pp_error "text/html"
-let return_html_internal_error = mk_return_fun pp_internal_error "text/html"
-let return_html_msg = mk_return_fun pp_msg "text/html"
-let return_html_raw = mk_return_fun null_pp "text/html"
+let return_html_error exn =
+ let pp_error s =
+ sprintf "%s\n<body>Http Getter error: <span style=\"color:red\">%s</span></body></html>"
+ (html_tag ~exn ()) s
+ in
+ mk_return_fun pp_error "text/xml"
+let return_html_internal_error exn =
+ let pp_internal_error s =
+ sprintf "%s\n<body>Http Getter Internal error: <span style=\"color:red\">%s</span></body></html>"
+ (html_tag ~exn ()) s
+ in
+ mk_return_fun pp_internal_error "text/xml"
+let return_html_msg = mk_return_fun pp_msg "text/xml"
+let return_html_raw = mk_return_fun null_pp "text/xml"
let return_xml_raw = mk_return_fun null_pp "text/xml"
-let return_400 body outchan =
- Http_daemon.respond_error ~code:(`Code 400) ~body outchan
+let return_400 exn body = return_html_error exn body
let return_all_foo_uris doctype uris outchan =
Http_daemon.send_basic_headers ~code:(`Code 200) outchan;
let return_list_servers outchan =
return_html_raw
- (sprintf "<html><body><table>\n%s\n</table></body></html>"
+ (sprintf "%s<body><table>\n%s\n</table></body></html>"
+ (html_tag ())
(String.concat "\n"
(List.map
(fun (pos, server) ->
* Channel is closed afterwards. *)
let send_log_to ?prepend action outchan =
Http_daemon.send_basic_headers ~code:(`Code 200) outchan;
- Http_daemon.send_header "Content-Type" "text/html" outchan;
+ Http_daemon.send_header "Content-Type" "text/xml" outchan;
Http_daemon.send_CRLF outchan;
- output_string outchan "<html><body>\n"; flush outchan;
+ output_string outchan (sprintf "%s<body>\n" (html_tag ()));
+ flush outchan;
(match prepend with
| None -> ()
| Some text -> output_string outchan text; flush outchan);
| Http_types.Param_not_found attr_name ->
let msg = sprintf "Parameter '%s' is missing" attr_name in
log_failure msg;
- return_400 msg outchan
+ return_400 ("bad_request", msg) msg outchan
| Bad_request msg ->
log_failure msg;
- return_html_error msg outchan
+ return_html_error ("bad_request", msg) msg outchan
| Internal_error msg ->
log_failure msg;
- return_html_internal_error msg outchan
+ return_html_internal_error ("internal_error", msg) msg outchan
| Shell.Subprocess_error l ->
let msgs =
List.map
sprintf "Command '%s' returned %s" cmd (string_of_proc_status code))
l
in
- log_failure (String.concat ", " msgs);
- return_html_internal_error (String.concat "<br />\n" msgs) outchan
- | exc ->
- let msg = "Uncaught exception: " ^ (Printexc.to_string exc) in
+ let msg = String.concat ", " msgs in
log_failure msg;
- return_html_error msg outchan
+ return_html_internal_error ("subprocess_error", msg)
+ (String.concat "<br />\n" msgs) outchan
+ | exc ->
+ let msg = "uncaught exception: " ^ (Printexc.to_string exc) in
+ (match exc with
+ | Http_getter_types.Key_not_found uri ->
+ return_html_error ("key_not_found", uri) msg outchan
+ | _ ->
+ log_failure msg;
+ return_html_error ("uncaught_exception", msg) msg outchan)
(* Main *)