aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http_hd.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-12-18 00:33:08 +0200
committerLoïc Hoguin <[email protected]>2014-12-18 00:33:08 +0200
commit4219ba2c9e7a8e4825d30d8f5a23d559d04dffa4 (patch)
treea105775b978fa56f66942ddc1faf5a4b47e263b3 /src/cow_http_hd.erl
parent8ebb992434c89e191389503cbc705d7f30706772 (diff)
downloadcowlib-4219ba2c9e7a8e4825d30d8f5a23d559d04dffa4.tar.gz
cowlib-4219ba2c9e7a8e4825d30d8f5a23d559d04dffa4.tar.bz2
cowlib-4219ba2c9e7a8e4825d30d8f5a23d559d04dffa4.zip
Add cow_http_hd:parse_if_none_match/1
From RFC7232.
Diffstat (limited to 'src/cow_http_hd.erl')
-rw-r--r--src/cow_http_hd.erl36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl
index 2c08486..aaec21d 100644
--- a/src/cow_http_hd.erl
+++ b/src/cow_http_hd.erl
@@ -25,6 +25,7 @@
-export([parse_expect/1]).
-export([parse_if_match/1]).
-export([parse_if_modified_since/1]).
+-export([parse_if_none_match/1]).
-export([parse_if_unmodified_since/1]).
-export([parse_last_modified/1]).
-export([parse_max_forwards/1]).
@@ -1103,6 +1104,41 @@ parse_if_modified_since_test_() ->
[{V, fun() -> R = parse_if_modified_since(V) end} || {V, R} <- Tests].
-endif.
+%% @doc Parse the If-None-Match header.
+
+-spec parse_if_none_match(binary()) -> '*' | [etag()].
+parse_if_none_match(<<"*">>) ->
+ '*';
+parse_if_none_match(IfNoneMatch) ->
+ nonempty(etag_list(IfNoneMatch, [])).
+
+-ifdef(TEST).
+parse_if_none_match_test_() ->
+ Tests = [
+ {<<"\"xyzzy\"">>, [{strong, <<"xyzzy">>}]},
+ {<<"W/\"xyzzy\"">>, [{weak, <<"xyzzy">>}]},
+ {<<"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\"">>,
+ [{strong, <<"xyzzy">>}, {strong, <<"r2d2xxxx">>}, {strong, <<"c3piozzzz">>}]},
+ {<<"W/\"xyzzy\", W/\"r2d2xxxx\", W/\"c3piozzzz\"">>,
+ [{weak, <<"xyzzy">>}, {weak, <<"r2d2xxxx">>}, {weak, <<"c3piozzzz">>}]},
+ {<<"*">>, '*'}
+ ],
+ [{V, fun() -> R = parse_if_none_match(V) end} || {V, R} <- Tests].
+
+parse_if_none_match_error_test_() ->
+ Tests = [
+ <<>>
+ ],
+ [{V, fun() -> {'EXIT', _} = (catch parse_if_none_match(V)) end} || V <- Tests].
+-endif.
+
+-ifdef(PERF).
+horse_parse_if_none_match() ->
+ horse:repeat(200000,
+ parse_if_none_match(<<"W/\"xyzzy\", W/\"r2d2xxxx\", W/\"c3piozzzz\"">>)
+ ).
+-endif.
+
%% @doc Parse the If-Unmodified-Since header.
-spec parse_if_unmodified_since(binary()) -> calendar:datetime().