Skip to content

Commit

Permalink
Make header comparison case-insensitive.
Browse files Browse the repository at this point in the history
According to RFC 2616 Section 4.2 header field names are
case-insensitive. The code was looking for an exact match for the
header name, which made it fail when connecting to servers who
(correctly) used different casing for the Sec-WebSocket-Accept
headers.

Reported by Adam Denenberg.

Fixes #1.
  • Loading branch information
wulczer committed May 24, 2012
1 parent 846e1ec commit 594157a
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/tsung/ts_websocket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,38 @@ get_message(#websocket_request{type=close, data=Data}, #state_rcv{session=Sessio
{make_frame(?OPCODE_CLOSE, Data), Session}.


% icase_equal(binary, binary) -> boolean
%
% compare two binary strings ignoring their case
icase_equal(A, B) ->
string:equal(string:to_lower(binary_to_list(A)),
string:to_lower(binary_to_list(B))).


% extract_header(binary, [binary]) -> binary
%
% Given a header name (binary) and a list of header lines, get the
% value for that header or an empty bitstring if the header is not
% present.
extract_header(Name, [Header | Tail]) ->
extract_header(Target, [Header | Tail]) ->
% get the header name and value
case binary:split(Header, << ": " >>) of
[Name, Val] ->
% found it
Val;
case icase_equal(Target, Name) of
true ->
% found the target header
Val;
_ ->
% not the header we're looking for
extract_header(Target, Tail)
end;
_ ->
% not the header we're looking for
extract_header(Name, Tail)
% the line did not include a ": ", ignore it
extract_header(Target, Tail)
end;
extract_header(Name, []) ->
extract_header(Target, []) ->
% the header was not found
?LOGF("WEBSOCKET: Header ~p not found ~n", [Name], ?NOTICE),
?LOGF("WEBSOCKET: Header ~p not found ~n", [Target], ?NOTICE),
<< >>.


Expand Down

0 comments on commit 594157a

Please sign in to comment.