Browse Source

Add cow_http_hd:parse_date/1

From RFC7231.
Loïc Hoguin 10 years ago
parent
commit
a2aa7c1554
1 changed files with 15 additions and 0 deletions
  1. 15 0
      src/cow_http_hd.erl

+ 15 - 0
src/cow_http_hd.erl

@@ -21,6 +21,7 @@
 -export([parse_connection/1]).
 -export([parse_content_length/1]).
 -export([parse_content_type/1]).
+-export([parse_date/1]).
 -export([parse_expect/1]).
 -export([parse_if_modified_since/1]).
 -export([parse_if_unmodified_since/1]).
@@ -942,6 +943,20 @@ horse_parse_content_type() ->
 	).
 -endif.
 
+%% @doc Parse the Date header.
+
+-spec parse_date(binary()) -> calendar:datetime().
+parse_date(Date) ->
+	http_date(Date).
+
+-ifdef(TEST).
+parse_date_test_() ->
+	Tests = [
+		{<<"Tue, 15 Nov 1994 08:12:31 GMT">>, {{1994, 11, 15}, {8, 12, 31}}}
+	],
+	[{V, fun() -> R = parse_date(V) end} || {V, R} <- Tests].
+-endif.
+
 %% @doc Parse the Expect header.
 
 -spec parse_expect(binary()) -> continue.