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 <zack@debian.org> Mon, 25 Nov 2002 11:04:49 +0100
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"
(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 =
| 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
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
(** 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
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
*)
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