diff options
author | Loïc Hoguin <[email protected]> | 2014-12-29 17:21:16 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-12-29 17:24:04 +0100 |
commit | 1c732125bfd12fb3a25997f93cdf9e418666bddb (patch) | |
tree | 08bdd4c839aef37e52181d9ca615d69da894e83a /src/cow_http.erl | |
parent | 779f4ad51c665092b1da5c8028dad6d62a5f76f0 (diff) | |
download | cowlib-1c732125bfd12fb3a25997f93cdf9e418666bddb.tar.gz cowlib-1c732125bfd12fb3a25997f93cdf9e418666bddb.tar.bz2 cowlib-1c732125bfd12fb3a25997f93cdf9e418666bddb.zip |
Add cow_http_hd:parse_host/1, remove cow_http:parse_fullhost/1
From RFC7230 and RFC3986.
The new function now validates that the characters are correct,
but does not go as far as validate segment sizes or number of
segments. Its main purpose is still to split host and port.
Diffstat (limited to 'src/cow_http.erl')
-rw-r--r-- | src/cow_http.erl | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/src/cow_http.erl b/src/cow_http.erl index 8504a21..7bb0562 100644 --- a/src/cow_http.erl +++ b/src/cow_http.erl @@ -18,7 +18,6 @@ -export([parse_status_line/1]). -export([parse_headers/1]). --export([parse_fullhost/1]). -export([parse_fullpath/1]). -export([parse_version/1]). @@ -200,72 +199,6 @@ horse_parse_headers() -> ). -endif. -%% @doc Extract host and port from a binary. -%% -%% Because the hostname is case insensitive it is converted -%% to lowercase. - --spec parse_fullhost(binary()) -> {binary(), undefined | non_neg_integer()}. -parse_fullhost(<< $[, Rest/bits >>) -> - parse_fullhost_ipv6(Rest, << $[ >>); -parse_fullhost(Fullhost) -> - parse_fullhost(Fullhost, <<>>). - -parse_fullhost_ipv6(<< $] >>, Acc) -> - {<< Acc/binary, $] >>, undefined}; -parse_fullhost_ipv6(<< $], $:, Rest/bits >>, Acc) -> - {<< Acc/binary, $] >>, binary_to_integer(Rest)}; -parse_fullhost_ipv6(<< C, Rest/bits >>, Acc) -> - case C of - ?INLINE_LOWERCASE(parse_fullhost_ipv6, Rest, Acc) - end. - -parse_fullhost(<<>>, Acc) -> - {Acc, undefined}; -parse_fullhost(<< $:, Rest/bits >>, Acc) -> - {Acc, binary_to_integer(Rest)}; -parse_fullhost(<< C, Rest/bits >>, Acc) -> - case C of - ?INLINE_LOWERCASE(parse_fullhost, Rest, Acc) - end. - --ifdef(TEST). -parse_fullhost_test() -> - {<<"example.org">>, 8080} = parse_fullhost(<<"example.org:8080">>), - {<<"example.org">>, undefined} = parse_fullhost(<<"example.org">>), - {<<"192.0.2.1">>, 8080} = parse_fullhost(<<"192.0.2.1:8080">>), - {<<"192.0.2.1">>, undefined} = parse_fullhost(<<"192.0.2.1">>), - {<<"[2001:db8::1]">>, 8080} = parse_fullhost(<<"[2001:db8::1]:8080">>), - {<<"[2001:db8::1]">>, undefined} = parse_fullhost(<<"[2001:db8::1]">>), - {<<"[::ffff:192.0.2.1]">>, 8080} - = parse_fullhost(<<"[::ffff:192.0.2.1]:8080">>), - {<<"[::ffff:192.0.2.1]">>, undefined} - = parse_fullhost(<<"[::ffff:192.0.2.1]">>), - ok. --endif. - --ifdef(PERF). -horse_parse_fullhost_blue_example_org() -> - horse:repeat(200000, - parse_fullhost(<<"blue.example.org:8080">>) - ). - -horse_parse_fullhost_ipv4() -> - horse:repeat(200000, - parse_fullhost(<<"192.0.2.1:8080">>) - ). - -horse_parse_fullhost_ipv6() -> - horse:repeat(200000, - parse_fullhost(<<"[2001:db8::1]:8080">>) - ). - -horse_parse_fullhost_ipv6_v4() -> - horse:repeat(200000, - parse_fullhost(<<"[::ffff:192.0.2.1]:8080">>) - ). --endif. - %% @doc Extract path and query string from a binary. -spec parse_fullpath(binary()) -> {binary(), binary()}. |