diff --git a/src/Tiny_httpd_util.ml b/src/Tiny_httpd_util.ml index 1822386d..d2507b01 100644 --- a/src/Tiny_httpd_util.ml +++ b/src/Tiny_httpd_util.ml @@ -66,11 +66,20 @@ let percent_decode (s:string) : _ option = exception Invalid_query +let find_q_index_ s = String.index s '?' + +let get_non_query_path s = + match find_q_index_ s with + | i -> String.sub s 0 i + | exception Not_found -> s + let get_query s : string = - match String.index s '?' with + match find_q_index_ s with | i -> String.sub s (i+1) (String.length s-i-1) | exception Not_found -> "" +let split_query s = get_non_query_path s, get_query s + let parse_query s : (_ list, string) result= let pairs = ref [] in let is_sep_ = function '&' | ';' -> true | _ -> false in diff --git a/src/Tiny_httpd_util.mli b/src/Tiny_httpd_util.mli index e1ed5d36..72bfc282 100644 --- a/src/Tiny_httpd_util.mli +++ b/src/Tiny_httpd_util.mli @@ -13,8 +13,16 @@ val percent_decode : string -> string option (** Inverse operation of {!percent_encode}. Can fail since some strings are not valid percent encodings. *) +val split_query : string -> string * string +(** Split a path between the path and the query + @since NEXT_RELEASE *) + +val get_non_query_path : string -> string +(** get the part of the path that is not the query parameters. + @since NEXT_RELEASE *) + val get_query : string -> string -(** Obtain the query part of a path +(** Obtain the query part of a path. @since 0.4 *) val parse_query : string -> ((string*string) list, string) result