From: Stefano Zacchiroli Date: Tue, 26 Nov 2002 15:40:03 +0000 (+0000) Subject: - added support for empty bindings like "a=" or simple "a" in query X-Git-Tag: V_0_0_6~52 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=ad1730728e7e9f64f3ba6b80940e9f190c50d6e8;p=helm.git - added support for empty bindings like "a=" or simple "a" in query arguments - s/Malformed_query_binding/Malformed_query_part/g --- diff --git a/helm/DEVEL/ocaml-http/debian/changelog b/helm/DEVEL/ocaml-http/debian/changelog index 6c6e399a7..5379f47a4 100644 --- a/helm/DEVEL/ocaml-http/debian/changelog +++ b/helm/DEVEL/ocaml-http/debian/changelog @@ -1,7 +1,9 @@ ocaml-http (0.0.6) unstable; urgency=low * Added support for multiple binding of the same parameter in request - objects (new method: 'param_all') + objects (new method: 'paramAll') + * Added support for 'empty' bindings in query arguments (e.g. "/foo?b=" or + "/foo?b") -- Stefano Zacchiroli Mon, 25 Nov 2002 11:04:49 +0100 diff --git a/helm/DEVEL/ocaml-http/examples/dump_args.ml b/helm/DEVEL/ocaml-http/examples/dump_args.ml index c1f445f12..ef4630fde 100644 --- a/helm/DEVEL/ocaml-http/examples/dump_args.ml +++ b/helm/DEVEL/ocaml-http/examples/dump_args.ml @@ -19,6 +19,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) +open Printf;; + let dump_args path args = Printf.sprintf "PATH: %s\nARGS:\n%s" @@ -26,7 +28,7 @@ let dump_args path args = (String.concat "" (List.map - (fun (name, value) -> "\tNAME: " ^ name ^ ", VALUE: " ^ value ^ "\n") + (fun (name, value) -> sprintf "\tNAME: '%s', VALUE: '%s'\n" name value) args)) in let callback path args outchan = diff --git a/helm/DEVEL/ocaml-http/http_daemon.ml b/helm/DEVEL/ocaml-http/http_daemon.ml index 0a0f47775..f2f70a037 100644 --- a/helm/DEVEL/ocaml-http/http_daemon.ml +++ b/helm/DEVEL/ocaml-http/http_daemon.ml @@ -313,11 +313,11 @@ let start | Malformed_query query -> respond_error ~code:400 ~body:(sprintf "Malformed query string '%s'" query) outchan - | Malformed_query_binding (binding, query) -> + | Malformed_query_part (binding, query) -> respond_error ~code:400 ~body:( - sprintf "Malformed query element '%s' in query '%s'" binding query) + sprintf "Malformed query part '%s' in query '%s'" binding query) outchan in match mode with diff --git a/helm/DEVEL/ocaml-http/http_parser.ml b/helm/DEVEL/ocaml-http/http_parser.ml index 87b910010..8a16398e8 100644 --- a/helm/DEVEL/ocaml-http/http_parser.ml +++ b/helm/DEVEL/ocaml-http/http_parser.ml @@ -23,7 +23,7 @@ open Neturl;; open Printf;; exception Malformed_query of string -exception Malformed_query_binding of string * string +exception Malformed_query_part of string * string exception Unsupported_method of string exception Unsupported_HTTP_version of string exception Malformed_request_URI of string @@ -56,7 +56,7 @@ let request_uri_syntax = { (** given an HTTP like query string (e.g. "name1=value1&name2=value2&...") @return a list of pairs [("name1", "value1"); ("name2", "value2")] @raise Malformed_query if the string isn't a valid query string - @raise Malformed_query_binding if some piece of the query isn't valid + @raise Malformed_query_part if some piece of the query isn't valid *) let split_query_params = let (bindings_sep, binding_sep) = (Pcre.regexp "&", Pcre.regexp "=") in @@ -67,12 +67,11 @@ let split_query_params = raise (Malformed_query query); List.map (fun binding -> - let pieces = Pcre.split ~rex:binding_sep binding in - if List.length pieces <> 2 then - raise (Malformed_query_binding (binding, query)); - (match pieces with - | [a; b] -> (http_decode a, http_decode b) - | _ -> assert false)) + match Pcre.split ~rex:binding_sep binding with + | [""; b] -> (* '=b' *) raise (Malformed_query_part (binding, query)) + | [a; b] -> (* 'a=b' *) (http_decode a, http_decode b) + | [a] -> (* 'a=' || 'a' *) (http_decode a, "") + | _ -> raise (Malformed_query_part (binding, query))) bindings (** given an input channel and a separator diff --git a/helm/DEVEL/ocaml-http/http_parser.mli b/helm/DEVEL/ocaml-http/http_parser.mli index 1cffb2a4a..6ccc67526 100644 --- a/helm/DEVEL/ocaml-http/http_parser.mli +++ b/helm/DEVEL/ocaml-http/http_parser.mli @@ -20,7 +20,7 @@ *) exception Malformed_query of string -exception Malformed_query_binding of string * string +exception Malformed_query_part of string * string exception Unsupported_method of string exception Unsupported_HTTP_version of string exception Malformed_request_URI of string diff --git a/helm/DEVEL/ocaml-http/http_request.ml b/helm/DEVEL/ocaml-http/http_request.ml index c95d19846..c2d972895 100644 --- a/helm/DEVEL/ocaml-http/http_request.ml +++ b/helm/DEVEL/ocaml-http/http_request.ml @@ -39,7 +39,7 @@ class request ~path ~params = Hashtbl.find params_tbl name with Not_found -> raise (Param_not_found name) - method param_all name = List.rev (Hashtbl.find_all params_tbl name) + method paramAll name = List.rev (Hashtbl.find_all params_tbl name) method params = params end