diff options
author | Loïc Hoguin <[email protected]> | 2015-03-12 17:31:28 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2015-03-12 17:31:28 +0100 |
commit | 3829db47a6453f412c8dbe60b246c9bdf2d9c327 (patch) | |
tree | 788f7045700ff0527b14720e36397a644b1168ed | |
parent | 4a1d9336bdbca6df1475cf6ef51994e91bdc4d2d (diff) | |
parent | 4767eb4f55135ab4bedc66dcbe70eb43bb32d406 (diff) | |
download | cowlib-3829db47a6453f412c8dbe60b246c9bdf2d9c327.tar.gz cowlib-3829db47a6453f412c8dbe60b246c9bdf2d9c327.tar.bz2 cowlib-3829db47a6453f412c8dbe60b246c9bdf2d9c327.zip |
Merge branch 'master' of https://github.com/camshaft/cowlib
-rw-r--r-- | src/cow_spdy.erl | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/cow_spdy.erl b/src/cow_spdy.erl index a906ddf..052bb43 100644 --- a/src/cow_spdy.erl +++ b/src/cow_spdy.erl @@ -284,13 +284,36 @@ settings_frame_test() -> -endif. build_headers(Zdef, Headers) -> - NbHeaders = length(Headers), + DedupedHeaders = dedupe_headers(Headers, []), + NbHeaders = length(DedupedHeaders), Headers2 = [begin L1 = iolist_size(Key), L2 = iolist_size(Value), [<< L1:32 >>, Key, << L2:32 >>, Value] - end || {Key, Value} <- Headers], + end || {Key, Value} <- DedupedHeaders], zlib:deflate(Zdef, [<< NbHeaders:32 >>, Headers2], full). +dedupe_headers([], Acc) -> + lists:reverse(Acc); +dedupe_headers([{Key, Value}|Headers], Acc) -> + Acc2 = append_header_value(Key, Value, Acc, []), + dedupe_headers(Headers, Acc2). + +append_header_value(Key, Value, [], Acc) -> + [{Key, Value}|Acc]; +append_header_value(Key, Value, [{Key, PrevValue}|Rest], Acc) -> + [{Key, [PrevValue, 0, Value]}|Rest] ++ Acc; +append_header_value(Key, Value, [Header|Headers], Acc) -> + append_header_value(Key, Value, Headers, [Header|Acc]). + +-ifdef(TEST). +dedupe_headers_test_() -> + Tests = [ + {[{<<"set-cookie">>, <<"session=123">>}, {<<"set-cookie">>, <<"other=456">>}, {<<"content-type">>, <<"text/html">>}], + [{<<"set-cookie">>, [<<"session=123">>, 0, <<"other=456">>]}, {<<"content-type">>, <<"text/html">>}]} + ], + [fun() -> D = dedupe_headers(R, []) end || {R, D} <- Tests]. +-endif. + to_flag(false) -> 0; to_flag(true) -> 1. |