aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http_hd.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-12-12 20:29:28 +0200
committerLoïc Hoguin <[email protected]>2014-12-12 20:29:28 +0200
commit63f2e99b39c98354077f96015370506e5745a109 (patch)
tree964677500d7c29bf17c9d0d10828d9e9761a1dd1 /src/cow_http_hd.erl
parent9485f21cc2efb1d013b72c1f0ba47e0589ed7ea8 (diff)
downloadcowlib-63f2e99b39c98354077f96015370506e5745a109.tar.gz
cowlib-63f2e99b39c98354077f96015370506e5745a109.tar.bz2
cowlib-63f2e99b39c98354077f96015370506e5745a109.zip
Add cow_http_hd:parse_max_forwards/1
From RFC7231.
Diffstat (limited to 'src/cow_http_hd.erl')
-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 13bab30..9a920a9 100644
--- a/src/cow_http_hd.erl
+++ b/src/cow_http_hd.erl
@@ -17,6 +17,7 @@
-export([parse_connection/1]).
-export([parse_content_length/1]).
-export([parse_expect/1]).
+-export([parse_max_forwards/1]).
-export([parse_transfer_encoding/1]).
-include("cow_inline.hrl").
@@ -143,6 +144,33 @@ horse_parse_expect() ->
).
-endif.
+%% @doc Parse the Max-Forwards header.
+
+-spec parse_max_forwards(binary()) -> integer().
+parse_max_forwards(<< $0, R/bits >>) -> number(R, 0);
+parse_max_forwards(<< $1, R/bits >>) -> number(R, 1);
+parse_max_forwards(<< $2, R/bits >>) -> number(R, 2);
+parse_max_forwards(<< $3, R/bits >>) -> number(R, 3);
+parse_max_forwards(<< $4, R/bits >>) -> number(R, 4);
+parse_max_forwards(<< $5, R/bits >>) -> number(R, 5);
+parse_max_forwards(<< $6, R/bits >>) -> number(R, 6);
+parse_max_forwards(<< $7, R/bits >>) -> number(R, 7);
+parse_max_forwards(<< $8, R/bits >>) -> number(R, 8);
+parse_max_forwards(<< $9, R/bits >>) -> number(R, 9).
+
+-ifdef(TEST).
+parse_max_forwards_test_() ->
+ Tests = [
+ {<<"0">>, 0},
+ {<<"42 ">>, 42},
+ {<<"69\t">>, 69},
+ {<<"1337">>, 1337},
+ {<<"1234567890">>, 1234567890},
+ {<<"1234567890 ">>, 1234567890}
+ ],
+ [{V, fun() -> R = parse_max_forwards(V) end} || {V, R} <- Tests].
+-endif.
+
%% @doc Parse the Transfer-Encoding header.
%%
%% @todo Extension parameters.