aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-12-19 12:46:05 +0200
committerLoïc Hoguin <[email protected]>2014-12-19 12:46:05 +0200
commita2376de4de4c01ac8cdf23983b0eb450ddc49a8b (patch)
tree0139625c4f308dce56063095a86e6f3c9f308bf9 /src
parent4ca82cae43b273e0afab8ef06000098044f006c0 (diff)
downloadcowlib-a2376de4de4c01ac8cdf23983b0eb450ddc49a8b.tar.gz
cowlib-a2376de4de4c01ac8cdf23983b0eb450ddc49a8b.tar.bz2
cowlib-a2376de4de4c01ac8cdf23983b0eb450ddc49a8b.zip
Add cow_http_hd:parse_content_encoding/1
From RFC7231.
Diffstat (limited to 'src')
-rw-r--r--src/cow_http_hd.erl28
1 files changed, 28 insertions, 0 deletions
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.