From 97a22d3cb86129f40451bb9a292fd3612829b829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 20 Dec 2014 12:35:25 +0200 Subject: Add cow_http_hd:parse_trailer/1 From RFC7230. --- 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 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. -- cgit v1.2.3