From 972609042f5b3fe52d53125392209252989862d6 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Fri, 6 Dec 2002 17:04:10 +0000 Subject: [PATCH] implemented and exported heal_header_name and heal_header_value --- helm/DEVEL/ocaml-http/http_parser.ml | 32 +++++++++++++++++++-------- helm/DEVEL/ocaml-http/http_parser.mli | 9 ++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/helm/DEVEL/ocaml-http/http_parser.ml b/helm/DEVEL/ocaml-http/http_parser.ml index 164f41324..00f8a6818 100644 --- a/helm/DEVEL/ocaml-http/http_parser.ml +++ b/helm/DEVEL/ocaml-http/http_parser.ml @@ -68,7 +68,18 @@ let field_content_RE_raw = separators_RE_raw quoted_string_RE_raw text_RE_raw +(* + (* following RFC 2616 specifications *) let field_value_RE_raw = "((" ^ field_content_RE_raw ^ ")|(" ^ lws_RE_raw^ "))*" +*) + (* smarter implementation: TEXT production is included in the regexp below *) +let field_value_RE_raw = + sprintf + "^((%s)|(%s)|(%s)|(%s))*$" + token_RE_raw + separators_RE_raw + quoted_string_RE_raw + lws_RE_raw let token_RE = Pcre.regexp ("^" ^ token_RE_raw ^ "$") let field_value_RE = Pcre.regexp ("^" ^ field_value_RE_raw ^ "$") @@ -77,11 +88,15 @@ let is_token s = Pcre.pmatch ~rex:token_RE s let is_field_name = is_token let is_field_value s = Pcre.pmatch ~rex:field_value_RE s +let heal_header_name s = + if not (is_field_name s) then raise (Invalid_header_name s) else () + +let heal_header_value s = + if not (is_field_value s) then raise (Invalid_header_value s) else () + let heal_header (name, value) = - if not (is_field_name name && is_field_value value) then - raise (Invalid_header (name ^ ": " ^ value)) - else - () + heal_header_name name; + heal_header_value name (** given an HTTP like query string (e.g. "name1=value1&name2=value2&...") @return a list of pairs [("name1", "value1"); ("name2", "value2")] @@ -141,11 +156,6 @@ let generic_input_line ~sep ~ic = else !line - (** given an input channel, reads from it a GET HTTP request and - @return a pair where path is a string representing the - requested path and query_params is a list of pairs (the GET - parameters) - *) let parse_request = let patch_empty_path s = (if s = "" then "/" else s) in let pieces_sep = Pcre.regexp " " in @@ -182,3 +192,7 @@ let parse_request = (path, query_params) | _ -> raise (Malformed_request request_line) +let parse_request' ic = + let (path, params) = parse_request ic in + new Http_request.request ~path ~params + diff --git a/helm/DEVEL/ocaml-http/http_parser.mli b/helm/DEVEL/ocaml-http/http_parser.mli index 8aa5562bd..4e70c35e4 100644 --- a/helm/DEVEL/ocaml-http/http_parser.mli +++ b/helm/DEVEL/ocaml-http/http_parser.mli @@ -19,7 +19,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) +val heal_header_name: string -> unit +val heal_header_value: string -> unit val heal_header: string * string -> unit + (** given an input channel, reads from it a GET HTTP request and + @return a pair where path is a string representing the + requested path and query_params is a list of pairs (the GET + parameters) *) val parse_request: in_channel -> string * (string * string) list + (** as above, but return an Http_types.request instance *) +val parse_request': in_channel -> Http_types.request + -- 2.39.2