with Http_types.Param_not_found _ -> true
(* parse output format ("format" parameter), no default value *)
-let parse_output_format (req: Http_types.request) =
+let parse_output_format meth (req: Http_types.request) =
match req#param "format" with
| s when String.lowercase s = "txt" -> Fmt_text
| s when String.lowercase s = "xml" -> Fmt_xml
- | s -> raise (Bad_request ("Invalid /ls format: " ^ s))
+ | s -> raise (Bad_request ("Invalid /" ^ meth ^ " format: " ^ s))
(* parse "baseuri" format for /ls method, no default value *)
let parse_ls_uri =
uris;
output_string outchan (sprintf "</%s>\n" doctype)
-let return_all_xml_uris outchan =
- return_all_foo_uris "alluris" (Http_getter.getalluris ()) outchan
+let return_all_xml_uris fmt outchan =
+ let uris = Http_getter.getalluris () in
+ match fmt with
+ | Fmt_text ->
+ let buf = Buffer.create 10240 in
+ List.iter (bprintf buf "%s\n") uris ;
+ let body = Buffer.contents buf in
+ Http_daemon.respond
+ ~headers:(("Content-Type", "text/plain") :: common_headers)
+ ~body outchan
+ | Fmt_xml ->
+ return_all_foo_uris "alluris" uris outchan
+
let return_all_rdf_uris classs outchan =
return_all_foo_uris "allrdfuris" (Http_getter.getallrdfuris classs) outchan
(sprintf "Removed server at position %d<br />\n%s"
position (HelmLogger.html_of_html_msg log))
outchan
- | "/getalluris" -> return_all_xml_uris outchan
+ | "/getalluris" ->
+ return_all_xml_uris (parse_output_format "getalluris" req) outchan
| "/getallrdfuris" -> return_all_rdf_uris (parse_rdf_class req) outchan
- | "/ls" -> return_ls (parse_ls_uri req) (parse_output_format req) outchan
+ | "/ls" ->
+ return_ls (parse_ls_uri req) (parse_output_format "ls" req) outchan
| "/getempty" ->
Http_daemon.respond ~body:Http_getter_const.empty_xml outchan
| invalid_request ->