Permalink
Browse files

Fix the parsing of the Connection header

  • Loading branch information...
essen committed Oct 4, 2012
1 parent 3969b51 commit 7367f07ca00c4fa4dd14792cc95251ef9c9207b1
Showing with 12 additions and 9 deletions.
  1. +12 −9 src/cowboy_req.erl
View
@@ -1183,7 +1183,7 @@ parse_connection(<<>>, Acc, Token) ->
lists:reverse([Token|Acc]);
parse_connection(<< C, Rest/bits >>, Acc, Token)
when C =:= $,; C =:= $\s; C =:= $\t ->
- parse_connection_after(Rest, [Token|Acc]);
+ parse_connection_before(Rest, [Token|Acc]);
parse_connection(<< C, Rest/bits >>, Acc, Token) ->
case C of
$A -> parse_connection(Rest, Acc, << Token/binary, $a >>);
@@ -1215,14 +1215,6 @@ parse_connection(<< C, Rest/bits >>, Acc, Token) ->
C -> parse_connection(Rest, Acc, << Token/binary, C >>)
end.
-parse_connection_after(<<>>, Acc) ->
- lists:reverse(Acc);
-parse_connection_after(<< $,, Rest/bits >>, Acc) ->
- parse_connection_before(Rest, Acc);
-parse_connection_after(<< C, Rest/bits >>, Acc)
- when C =:= $\s; C =:= $\t ->
- parse_connection_after(Rest, Acc).
-
%% @doc Walk through a tokens list and return whether
%% the connection is keepalive or closed.
%%
@@ -1333,6 +1325,17 @@ url_test() ->
pid=self()}),
ok.
+parse_connection_test_() ->
+ %% {Binary, Result}
+ Tests = [
+ {<<"close">>, [<<"close">>]},
+ {<<"ClOsE">>, [<<"close">>]},
+ {<<"Keep-Alive">>, [<<"keep-alive">>]},
+ {<<"keep-alive, Upgrade">>, [<<"keep-alive">>, <<"upgrade">>]}
+ ],
+ [{B, fun() -> R = parse_connection_before(B, []) end}
+ || {B, R} <- Tests].
+
connection_to_atom_test_() ->
%% {Tokens, Result}
Tests = [

0 comments on commit 7367f07

Please sign in to comment.