aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 8fe9f04..0511e9d 100644
--- a/src/cow_http_hd.erl
+++ b/src/cow_http_hd.erl
@@ -36,6 +36,7 @@
-export([parse_sec_websocket_extensions/1]).
-export([parse_sec_websocket_protocol_client/1]).
-export([parse_sec_websocket_version_client/1]).
+-export([parse_trailer/1]).
-export([parse_transfer_encoding/1]).
-export([parse_upgrade/1]).
@@ -1808,6 +1809,33 @@ horse_parse_sec_websocket_version_client_255() ->
).
-endif.
+%% @doc Parse the Trailer header.
+
+-spec parse_trailer(binary()) -> [binary()].
+parse_trailer(Trailer) ->
+ nonempty(token_ci_list(Trailer, [])).
+
+-ifdef(TEST).
+parse_trailer_test_() ->
+ Tests = [
+ {<<"Date, Content-MD5">>, [<<"date">>, <<"content-md5">>]}
+ ],
+ [{V, fun() -> R = parse_trailer(V) end} || {V, R} <- Tests].
+
+parse_trailer_error_test_() ->
+ Tests = [
+ <<>>
+ ],
+ [{V, fun() -> {'EXIT', _} = (catch parse_trailer(V)) end} || V <- Tests].
+-endif.
+
+-ifdef(PERF).
+horse_parse_trailer() ->
+ horse:repeat(200000,
+ parse_trailer(<<"Date, Content-MD5">>)
+ ).
+-endif.
+
%% @doc Parse the Transfer-Encoding header.
%%
%% @todo This function does not support parsing of transfer-parameter.