From: Stefano Zacchiroli Date: Fri, 10 Jan 2003 17:23:12 +0000 (+0000) Subject: debugging print of HTTP request's parsing errors X-Git-Tag: v0_3_99~37 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=e8466faa2922f4bb480a87e88435bf0ddc26a747;p=helm.git debugging print of HTTP request's parsing errors --- diff --git a/helm/DEVEL/ocaml-http/debian/changelog b/helm/DEVEL/ocaml-http/debian/changelog index cdf4c48f0..9a99ea51d 100644 --- a/helm/DEVEL/ocaml-http/debian/changelog +++ b/helm/DEVEL/ocaml-http/debian/changelog @@ -3,6 +3,9 @@ ocaml-http (0.0.8) unstable; urgency=low * Added support for "ancient" HTTP requests which specify no HTTP version - 'version' method on message now has type 'version option' + * Http_daemon now use debugging prints from Http_common like other + modules + * Added debugging print of requests parse error -- Stefano Zacchiroli Fri, 10 Jan 2003 10:36:53 +0100 diff --git a/helm/DEVEL/ocaml-http/http_daemon.ml b/helm/DEVEL/ocaml-http/http_daemon.ml index 9e49551f4..5b621bf55 100644 --- a/helm/DEVEL/ocaml-http/http_daemon.ml +++ b/helm/DEVEL/ocaml-http/http_daemon.ml @@ -26,13 +26,6 @@ open Http_types;; open Http_constants;; open Http_parser;; -let debug = true -let debug_print str = - if debug then begin - prerr_endline ("DEBUG: " ^ str); - flush stderr - end - let default_addr = "0.0.0.0" let default_port = 80 let default_timeout = 300 @@ -281,6 +274,9 @@ let respond_with (res: Http_types.response) outchan = skip to next request *) exception Again;; +let pp_parse_exc e = + sprintf "HTTP request parse error: %s" (Printexc.to_string e) + (* given a Http_parser.parse_request like function, wrap it in a function that do the same and additionally catch parsing exception sending HTTP error messages back to client as needed. Returned function raises Again when it @@ -292,10 +288,12 @@ let rec wrap_parse_request_w_safety parse_function inchan outchan = (try parse_function inchan with - | End_of_file -> + | (End_of_file) as e -> + debug_print (pp_parse_exc e); respond_error ~code:400 ~body:"Unexpected End Of File" outchan; raise Again - | Malformed_request req -> + | (Malformed_request req) as e -> + debug_print (pp_parse_exc e); respond_error ~code:400 ~body:( @@ -303,26 +301,31 @@ let rec wrap_parse_request_w_safety parse_function inchan outchan = "
\nwhile received request 1st line was:
\n" ^ req) outchan; raise Again - | Unsupported_method meth -> + | (Unsupported_method meth) as e -> + debug_print (pp_parse_exc e); respond_error ~code:501 ~body:("Method '" ^ meth ^ "' isn't supported (yet)") outchan; raise Again - | Malformed_request_URI uri -> + | (Malformed_request_URI uri) as e -> + debug_print (pp_parse_exc e); respond_error ~code:400 ~body:("Malformed URL: '" ^ uri ^ "'") outchan; raise Again - | Unsupported_HTTP_version version -> + | (Unsupported_HTTP_version version) as e -> + debug_print (pp_parse_exc e); respond_error ~code:505 ~body:("HTTP version '" ^ version ^ "' isn't supported (yet)") outchan; raise Again - | Malformed_query query -> + | (Malformed_query query) as e -> + debug_print (pp_parse_exc e); respond_error ~code:400 ~body:(sprintf "Malformed query string '%s'" query) outchan; raise Again - | Malformed_query_part (binding, query) -> + | (Malformed_query_part (binding, query)) as e -> + debug_print (pp_parse_exc e); respond_error ~code:400 ~body:(