aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-12-26 14:34:44 +0100
committerLoïc Hoguin <[email protected]>2014-12-26 14:34:44 +0100
commit092ef3d91b07ed0470ccfaba339d45986f65e40a (patch)
tree94e2c40517e2ee1a95b2fbb3a40a77010093ba04 /src
parent70f438de744155d5d1e5c1716ccf640cc1c0c95d (diff)
downloadcowlib-092ef3d91b07ed0470ccfaba339d45986f65e40a.tar.gz
cowlib-092ef3d91b07ed0470ccfaba339d45986f65e40a.tar.bz2
cowlib-092ef3d91b07ed0470ccfaba339d45986f65e40a.zip
Add cow_http_hd:parse_if_range/1
From RFC7233.
Diffstat (limited to 'src')
-rw-r--r--src/cow_http_hd.erl39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl
index 584309c..e9417cf 100644
--- a/src/cow_http_hd.erl
+++ b/src/cow_http_hd.erl
@@ -34,6 +34,7 @@
-export([parse_if_match/1]).
-export([parse_if_modified_since/1]).
-export([parse_if_none_match/1]).
+-export([parse_if_range/1]).
-export([parse_if_unmodified_since/1]).
-export([parse_last_modified/1]).
-export([parse_max_forwards/1]).
@@ -1835,6 +1836,44 @@ horse_parse_if_none_match() ->
).
-endif.
+%% @doc Parse the If-Range header.
+
+-spec parse_if_range(binary()) -> etag() | calendar:datetime().
+parse_if_range(<< $W, $/, $", R/bits >>) ->
+ etag(R, weak, <<>>);
+parse_if_range(<< $", R/bits >>) ->
+ etag(R, strong, <<>>);
+parse_if_range(IfRange) ->
+ cow_date:parse_date(IfRange).
+
+-ifdef(TEST).
+parse_if_range_test_() ->
+ Tests = [
+ {<<"W/\"xyzzy\"">>, {weak, <<"xyzzy">>}},
+ {<<"\"xyzzy\"">>, {strong, <<"xyzzy">>}},
+ {<<"Sat, 29 Oct 1994 19:43:31 GMT">>, {{1994, 10, 29}, {19, 43, 31}}}
+ ],
+ [{V, fun() -> R = parse_if_range(V) end} || {V, R} <- Tests].
+
+parse_if_range_error_test_() ->
+ Tests = [
+ <<>>
+ ],
+ [{V, fun() -> {'EXIT', _} = (catch parse_if_range(V)) end} || V <- Tests].
+-endif.
+
+-ifdef(PERF).
+horse_parse_if_range_etag() ->
+ horse:repeat(200000,
+ parse_if_range(<<"\"xyzzy\"">>)
+ ).
+
+horse_parse_if_range_date() ->
+ horse:repeat(200000,
+ parse_if_range(<<"Sat, 29 Oct 1994 19:43:31 GMT">>)
+ ).
+-endif.
+
%% @doc Parse the If-Unmodified-Since header.
-spec parse_if_unmodified_since(binary()) -> calendar:datetime().