let iter_file f = fold_file (fun _ line -> f line) ()
let (title_tag_RE, choices_tag_RE, msg_tag_RE, id_to_uris_RE, id_RE,
- interpretations_RE, interpretations_labels_RE, results_RE, new_aliases_RE) =
+ interpretations_RE, interpretations_labels_RE, results_RE, new_aliases_RE,
+ processorURL_RE)
+ =
(Pcre.regexp "@TITLE@", Pcre.regexp "@CHOICES@", Pcre.regexp "@MSG@",
Pcre.regexp "@ID_TO_URIS@", Pcre.regexp "@ID@",
Pcre.regexp "@INTERPRETATIONS@", Pcre.regexp "@INTERPRETATIONS_LABELS@",
- Pcre.regexp "@RESULTS@", Pcre.regexp "@NEW_ALIASES@")
+ Pcre.regexp "@RESULTS@", Pcre.regexp "@NEW_ALIASES@",
+ Pcre.regexp "@processorURL@")
let server_and_port_url_RE = Pcre.regexp "^http://([^/]+)/.*$"
let port =
(let is_permitted _ = true in
let remove_fragment uri = Pcre.replace ~pat:"#.*" uri in
let page = remove_fragment (req#param "url") in
- match page with
+ let preprocess =
+ (try
+ bool_of_string (req#param "preprocess")
+ with Invalid_argument _ | Http_types.Param_not_found _ -> false)
+ in
+ (match page with
| page when is_permitted page ->
- Http_daemon.respond_file
- ~fname:(sprintf "%s/%s" pages_dir (remove_fragment page)) outchan
- | page -> Http_daemon.respond_forbidden ~url:page outchan)
+ let fname = sprintf "%s/%s" pages_dir (remove_fragment page) in
+ if preprocess then begin
+ Http_daemon.send_basic_headers ~code:200 outchan;
+ Http_daemon.send_CRLF outchan;
+ iter_file
+ (fun line ->
+ output_string outchan
+ ((apply_substs
+ [processorURL_RE, req#param "processorURL"] line) ^
+ "\n"))
+ fname
+ end else
+ Http_daemon.respond_file ~fname outchan
+ | page -> Http_daemon.respond_forbidden ~url:page outchan))
| "/ask_uwobo" ->
let url = req#param "url" in
let server_and_port =