]> matita.cs.unibo.it Git - helm.git/commitdiff
debugging print of HTTP request's parsing errors
authorStefano Zacchiroli <zack@upsilon.cc>
Fri, 10 Jan 2003 17:23:12 +0000 (17:23 +0000)
committerStefano Zacchiroli <zack@upsilon.cc>
Fri, 10 Jan 2003 17:23:12 +0000 (17:23 +0000)
helm/DEVEL/ocaml-http/debian/changelog
helm/DEVEL/ocaml-http/http_daemon.ml

index cdf4c48f0321a38be2b3d471bd4d81f227b2dc29..9a99ea51d8af117683f1fe932887dd605cc6b97d 100644 (file)
@@ -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 <zack@debian.org>  Fri, 10 Jan 2003 10:36:53 +0100
 
index 9e49551f4c6ac742ceaebd1a3040cc624814b9d7..5b621bf55f8a6d176aa2565e21baa10bd590ef75 100644 (file)
@@ -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 =
           "<br />\nwhile received request 1st line was:<br />\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:(