mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-05 19:00:32 -05:00
feat(util): add some query related utils
This commit is contained in:
parent
995aee8489
commit
bdd2fd8160
2 changed files with 19 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue