From a2376de4de4c01ac8cdf23983b0eb450ddc49a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 19 Dec 2014 12:46:05 +0200 Subject: Add cow_http_hd:parse_content_encoding/1 From RFC7231. --- src/cow_http_hd.erl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl index 162e6ad..fd9f218 100644 --- a/src/cow_http_hd.erl +++ b/src/cow_http_hd.erl @@ -19,6 +19,7 @@ -export([parse_accept_encoding/1]). -export([parse_accept_language/1]). -export([parse_connection/1]). +-export([parse_content_encoding/1]). -export([parse_content_length/1]). -export([parse_content_type/1]). -export([parse_date/1]). @@ -758,6 +759,33 @@ horse_parse_connection_keepalive_upgrade() -> ). -endif. +%% @doc Parse the Content-Encoding header. + +-spec parse_content_encoding(binary()) -> [binary()]. +parse_content_encoding(ContentEncoding) -> + nonempty(token_ci_list(ContentEncoding, [])). + +-ifdef(TEST). +parse_content_encoding_test_() -> + Tests = [ + {<<"gzip">>, [<<"gzip">>]} + ], + [{V, fun() -> R = parse_content_encoding(V) end} || {V, R} <- Tests]. + +parse_content_encoding_error_test_() -> + Tests = [ + <<>> + ], + [{V, fun() -> {'EXIT', _} = (catch parse_content_encoding(V)) end} || V <- Tests]. +-endif. + +-ifdef(PERF). +horse_parse_content_encoding() -> + horse:repeat(200000, + parse_content_encoding(<<"gzip">>) + ). +-endif. + %% @doc Parse the Content-Length header. %% %% The value has at least one digit, and may be followed by whitespace. -- cgit v1.2.3