diff options
author | Henrik Nord <[email protected]> | 2015-10-27 12:46:47 +0100 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2015-10-27 12:46:47 +0100 |
commit | 5a36d9f631d1f22ea3b6ecc40dd647c33795a688 (patch) | |
tree | 9fb87ed248c0fc5b0a6763e60dbcbd278d5ad93f /lib/inets/src/http_lib/http_uri.erl | |
parent | 804ee95d85b50b1789c4506e5c83a6aa1316f33a (diff) | |
parent | 3b28f0d9bbc9e5745fb95e48e6daf9179461116b (diff) | |
download | otp-5a36d9f631d1f22ea3b6ecc40dd647c33795a688.tar.gz otp-5a36d9f631d1f22ea3b6ecc40dd647c33795a688.tar.bz2 otp-5a36d9f631d1f22ea3b6ecc40dd647c33795a688.zip |
Merge branch 'scrapinghub/http_uri_scheme_validation' into maint
* scrapinghub/http_uri_scheme_validation:
inets: scheme validation fun for http_uri
OTP-13071
Diffstat (limited to 'lib/inets/src/http_lib/http_uri.erl')
-rw-r--r-- | lib/inets/src/http_lib/http_uri.erl | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/inets/src/http_lib/http_uri.erl b/lib/inets/src/http_lib/http_uri.erl index 79591eec29..6fe8c1776d 100644 --- a/lib/inets/src/http_lib/http_uri.erl +++ b/lib/inets/src/http_lib/http_uri.erl @@ -138,16 +138,33 @@ parse_scheme(AbsURI, Opts) -> {error, no_scheme} -> {error, no_scheme}; {SchemeStr, Rest} -> - Scheme = list_to_atom(http_util:to_lower(SchemeStr)), - SchemeDefaults = which_scheme_defaults(Opts), - case lists:keysearch(Scheme, 1, SchemeDefaults) of - {value, {Scheme, DefaultPort}} -> - {Scheme, DefaultPort, Rest}; - false -> - {Scheme, no_default_port, Rest} + case extract_scheme(SchemeStr, Opts) of + {error, Error} -> + {error, Error}; + {ok, Scheme} -> + SchemeDefaults = which_scheme_defaults(Opts), + case lists:keysearch(Scheme, 1, SchemeDefaults) of + {value, {Scheme, DefaultPort}} -> + {Scheme, DefaultPort, Rest}; + false -> + {Scheme, no_default_port, Rest} + end end end. +extract_scheme(Str, Opts) -> + case lists:keysearch(scheme_validation_fun, 1, Opts) of + {value, {scheme_validation_fun, Fun}} when is_function(Fun) -> + case Fun(Str) of + valid -> + {ok, list_to_atom(http_util:to_lower(Str))}; + {error, Error} -> + {error, Error} + end; + _ -> + {ok, list_to_atom(http_util:to_lower(Str))} + end. + parse_uri_rest(Scheme, DefaultPort, "//" ++ URIPart, Opts) -> {Authority, PathQueryFragment} = split_uri(URIPart, "[/?#]", {URIPart, ""}, 1, 0), |