From 1c732125bfd12fb3a25997f93cdf9e418666bddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 29 Dec 2014 17:21:16 +0100 Subject: 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. --- src/cow_http.erl | 67 -------------------------------------------------------- 1 file changed, 67 deletions(-) (limited to 'src/cow_http.erl') 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()}. -- cgit v1.2.3