(* HTTP queries argument parsing *)
+ (* parse encoding ("format" parameter), default is Enc_normal *)
let parse_enc (req: Http_types.request) =
try
(match req#param "format" with
| s -> raise (Http_getter_bad_request ("Invalid format: " ^ s)))
with Http_types.Param_not_found _ -> Enc_normal
;;
+ (* parse "patch_dtd" parameter, default is true *)
let parse_patch (req: Http_types.request) =
- match req#param "patch_dtd" with
- | s when String.lowercase s = "yes" -> true
- | s when String.lowercase s = "no" -> false
- | s -> raise (Http_getter_bad_request ("Invalid patch_dtd value: " ^ s))
+ try
+ (match req#param "patch_dtd" with
+ | s when String.lowercase s = "yes" -> true
+ | s when String.lowercase s = "no" -> false
+ | s -> raise (Http_getter_bad_request ("Invalid patch_dtd value: " ^ s)))
+ with Http_types.Param_not_found _ -> true
;;
+ (* parse output format ("format" parameter), no default value *)
let parse_output_format (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 (Http_getter_bad_request ("Invalid /ls format: " ^ s))
;;
+ (* parse "baseuri" format for /ls method, no default value *)
let parse_ls_uri =
let parse_ls_RE = Pcre.regexp "^(\\w+):(.*)$" in
let trailing_slash_RE = Pcre.regexp "/+$" in
let (++) (oldann, oldtypes, oldbody) (newann, newtypes, newbody) =
((if newann > oldann then newann else oldann),
(if newtypes > oldtypes then newtypes else oldtypes),
- (if newbody > oldbody then newbody else oldbody))
- in
+ (if newbody > oldbody then newbody else oldbody))
+ in
let basepart_RE =
Pcre.regexp "^([^.]*\\.[^.]*)((\\.body)|(\\.types))?(\\.ann)?"
in
let oldflags =
try
Hashtbl.find objs basepart
- with Not_found -> (false, No, No) (* no ann, no types no body *)
+ with Not_found -> (false, No, No) (* no ann, no types, no body *)
in
let newflags =
match o with
in
Http_daemon.respond
~headers:(("Content-Type", "text/plain") :: common_headers)
- ~body outchan
+ ~body outchan
| Fmt_xml ->
let body =
sprintf
in
Http_daemon.respond
~headers:(("Content-Type", "text/xml") :: common_headers)
- ~body outchan
+ ~body outchan
in
let (index_line_sep_RE, index_sep_RE, trailing_types_RE,
heading_cic_RE, heading_theory_RE,
match req#path with
| "/getxml" ->
let enc = parse_enc req in
- let patch =
- try parse_patch req with Http_types.Param_not_found _ -> true
- in
+ let patch = parse_patch req in
Http_getter_cache.respond_xml
~url:(resolve uri) ~uri ~enc ~patch outchan
| "/getxslt" ->
- let patch =
- try parse_patch req with Http_types.Param_not_found _ -> true
- in
+ let patch = parse_patch req in
Http_getter_cache.respond_xsl ~url:(resolve uri) ~patch outchan
| "/getdtd" ->
- let patch =
- try parse_patch req with Http_types.Param_not_found _ -> true
- in
+ let patch = parse_patch req in
Http_getter_cache.respond_dtd
~patch ~url:(Http_getter_env.dtd_dir ^ "/" ^ uri) outchan
| "/resolve" ->