diff options
author | Loïc Hoguin <[email protected]> | 2014-12-12 19:42:20 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-12-12 19:42:20 +0200 |
commit | 9044538ed63075aaf44fb683b3da4202f41902c4 (patch) | |
tree | 7521503b09f4726b19c9bc3c297cf91f4f43f7d7 /src | |
parent | 7d8a571b1e50602d701ca203fbf28036b2cf80f5 (diff) | |
download | cowlib-9044538ed63075aaf44fb683b3da4202f41902c4.tar.gz cowlib-9044538ed63075aaf44fb683b3da4202f41902c4.tar.bz2 cowlib-9044538ed63075aaf44fb683b3da4202f41902c4.zip |
Add cow_http_hd:parse_expect/1
From RFC7231.
Diffstat (limited to 'src')
-rw-r--r-- | src/cow_http_hd.erl | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl index 35cf2f4..13bab30 100644 --- a/src/cow_http_hd.erl +++ b/src/cow_http_hd.erl @@ -16,6 +16,7 @@ -export([parse_connection/1]). -export([parse_content_length/1]). +-export([parse_expect/1]). -export([parse_transfer_encoding/1]). -include("cow_inline.hrl"). @@ -100,6 +101,48 @@ horse_parse_content_length_giga() -> ). -endif. +%% @doc Parse the Expect header. + +-spec parse_expect(binary()) -> continue. +parse_expect(<<"100-continue", Rest/bits >>) -> + ws_end(Rest), + continue; +parse_expect(<<"100-", C, O, N, T, I, M, U, E, Rest/bits >>) + when C =:= $C orelse C =:= $c, O =:= $O orelse O =:= $o, + N =:= $N orelse N =:= $n, T =:= $T orelse T =:= $t, + I =:= $I orelse I =:= $i, M =:= $N orelse M =:= $n, + U =:= $U orelse U =:= $u, E =:= $E orelse E =:= $e -> + ws_end(Rest), + continue. + +-ifdef(TEST). +parse_expect_test_() -> + Tests = [ + <<"100-continue">>, + <<"100-CONTINUE">>, + <<"100-Continue">>, + <<"100-CoNtInUe">>, + <<"100-continue ">> + ], + [{V, fun() -> continue = parse_expect(V) end} || V <- Tests]. + +parse_expect_error_test_() -> + Tests = [ + <<>>, + <<" ">>, + <<"200-OK">>, + <<"Cookies">> + ], + [{V, fun() -> {'EXIT', _} = (catch parse_expect(V)) end} || V <- Tests]. +-endif. + +-ifdef(PERF). +horse_parse_expect() -> + horse:repeat(200000, + parse_expect(<<"100-continue">>) + ). +-endif. + %% @doc Parse the Transfer-Encoding header. %% %% @todo Extension parameters. |