9 type url_syntax_option =
10 Url_part_not_recognized
14 * (1) scheme://user:password@host:port/path;params?query#fragment
17 let request_uri_syntax = {
18 url_enable_scheme = Url_part_not_recognized;
19 url_enable_user = Url_part_not_recognized;
20 url_enable_password = Url_part_not_recognized;
21 url_enable_host = Url_part_not_recognized;
22 url_enable_port = Url_part_not_recognized;
23 url_enable_path = Url_part_required;
24 url_enable_param = Url_part_not_recognized;
25 url_enable_query = Url_part_allowed;
26 url_enable_fragment = Url_part_not_recognized;
27 url_enable_other = Url_part_not_recognized;
28 url_accepts_8bits = false;
29 url_is_valid = (fun _ -> true);
33 foo_RE_raw is the uncompiled regexp matching foo
34 foo_RE is the compiled regexp matching foo
35 is_foo is the predicate over string matching foo
38 let separators_RE_raw = "()<>@,;:\\\\\"/\\[\\]?={} \t"
39 let ctls_RE_raw = "\\x00-\\x1F\\x7F"
40 let token_RE_raw = "[^" ^ separators_RE_raw ^ ctls_RE_raw ^ "]+"
41 let lws_RE_raw = "(\r\n)?[ \t]"
42 let quoted_string_RE_raw = "\"(([^\"])|(\\\\\"))*\""
43 let text_RE_raw = "(([^" ^ ctls_RE_raw ^ "])|(" ^ lws_RE_raw ^ "))+"
44 let field_content_RE_raw =
46 "^(((%s)|(%s)|(%s))|(%s))*$"
52 (* following RFC 2616 specifications *)
53 let field_value_RE_raw = "((" ^ field_content_RE_raw ^ ")|(" ^ lws_RE_raw^ "))*"
55 (* smarter implementation: TEXT production is included in the regexp below *)
56 let field_value_RE_raw =
58 "^((%s)|(%s)|(%s)|(%s))*$"
64 let token_RE = Pcre.regexp ("^" ^ token_RE_raw ^ "$")
65 let field_value_RE = Pcre.regexp ("^" ^ field_value_RE_raw ^ "$")
66 let heading_lws_RE = Pcre.regexp (sprintf "^%s*" lws_RE_raw)
67 let trailing_lws_RE = Pcre.regexp (sprintf "%s*$" lws_RE_raw)
69 let is_token s = Pcre.pmatch ~rex:token_RE s
70 let is_field_name = is_token
71 let is_field_value s = Pcre.pmatch ~rex:field_value_RE s
73 let heal_header_name s =
74 if not (is_field_name s) then raise (Invalid_header_name s) else ()
76 let heal_header_value s =
77 if not (is_field_value s) then raise (Invalid_header_value s) else ()
79 let normalize_header_value s =
80 Pcre.replace ~rex:trailing_lws_RE
81 (Pcre.replace ~rex:heading_lws_RE s)
83 let heal_header (name, value) =
84 heal_header_name name;
85 heal_header_value name
89 url_of_string request_uri_syntax s
90 with Neturl.Malformed_URL -> raise (Malformed_URL s)
91 let string_of_url = Neturl.string_of_url