aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http_hd.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/cow_http_hd.erl')
-rw-r--r--src/cow_http_hd.erl29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl
index b1bafaa..cf36b53 100644
--- a/src/cow_http_hd.erl
+++ b/src/cow_http_hd.erl
@@ -31,6 +31,7 @@
-export([parse_if_unmodified_since/1]).
-export([parse_last_modified/1]).
-export([parse_max_forwards/1]).
+-export([parse_sec_websocket_protocol_client/1]).
-export([parse_sec_websocket_version_client/1]).
-export([parse_transfer_encoding/1]).
-export([parse_upgrade/1]).
@@ -1294,6 +1295,34 @@ parse_max_forwards_error_test_() ->
[{V, fun() -> {'EXIT', _} = (catch parse_content_length(V)) end} || V <- Tests].
-endif.
+%% @doc Parse the Sec-WebSocket-Protocol request header.
+
+-spec parse_sec_websocket_protocol_client(binary()) -> [binary()].
+parse_sec_websocket_protocol_client(SecWebSocketProtocol) ->
+ nonempty(token_ci_list(SecWebSocketProtocol, [])).
+
+-ifdef(TEST).
+parse_sec_websocket_protocol_client_test_() ->
+ Tests = [
+ {<<"chat, superchat">>, [<<"chat">>, <<"superchat">>]}
+ ],
+ [{V, fun() -> R = parse_sec_websocket_protocol_client(V) end} || {V, R} <- Tests].
+
+parse_sec_websocket_protocol_client_error_test_() ->
+ Tests = [
+ <<>>
+ ],
+ [{V, fun() -> {'EXIT', _} = (catch parse_sec_websocket_protocol_client(V)) end}
+ || V <- Tests].
+-endif.
+
+-ifdef(PERF).
+horse_parse_sec_websocket_protocol_client() ->
+ horse:repeat(200000,
+ parse_sec_websocket_protocol_client(<<"chat, superchat">>)
+ ).
+-endif.
+
%% @doc Parse the Sec-WebSocket-Version request header.
-spec parse_sec_websocket_version_client(binary()) -> 0..255.