Browse Source

Add cow_http_hd:parse_pragma/1

We go for an exact <<"no-cache">> match because this is the only
directive that was ever defined, because the header is only kept
for backward compatible reasons with HTTP/1.0 caches, and because
for all other uses the cache-control header is preferred.
Loïc Hoguin 10 years ago
parent
commit
779f4ad51c
1 changed files with 14 additions and 0 deletions
  1. 14 0
      src/cow_http_hd.erl

+ 14 - 0
src/cow_http_hd.erl

@@ -39,6 +39,7 @@
 -export([parse_if_unmodified_since/1]).
 -export([parse_last_modified/1]).
 -export([parse_max_forwards/1]).
+-export([parse_pragma/1]).
 -export([parse_range/1]).
 -export([parse_retry_after/1]).
 -export([parse_sec_websocket_accept/1]).
@@ -2052,6 +2053,19 @@ parse_max_forwards_error_test_() ->
 	[{V, fun() -> {'EXIT', _} = (catch parse_max_forwards(V)) end} || V <- Tests].
 -endif.
 
+%% @doc Parse the Pragma header.
+%%
+%% Legacy header kept for backward compatibility with HTTP/1.0 caches.
+%% Only the "no-cache" directive was ever specified, and only for
+%% request messages.
+%%
+%% We take a large shortcut in the parsing of this header, expecting
+%% an exact match of "no-cache".
+
+-spec parse_pragma(binary()) -> cache | no_cache.
+parse_pragma(<<"no-cache">>) -> no_cache;
+parse_pragma(_) -> cache.
+
 %% @doc Parse the Range header.
 
 -spec parse_range(binary())