diff options
author | Loïc Hoguin <[email protected]> | 2014-12-18 13:23:34 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-12-18 13:23:34 +0200 |
commit | 4bd6a0b5ffee707f7b17c72b8a95782823c3ee6e (patch) | |
tree | 1f9771c4d8999c77a894f27f0c588a19425c5280 | |
parent | bfa660285fe7babf7e6f334d6517e4d119bd3d10 (diff) | |
download | cowlib-4bd6a0b5ffee707f7b17c72b8a95782823c3ee6e.tar.gz cowlib-4bd6a0b5ffee707f7b17c72b8a95782823c3ee6e.tar.bz2 cowlib-4bd6a0b5ffee707f7b17c72b8a95782823c3ee6e.zip |
Add cow_http_hd:parse_sec_websocket_protocol_client/1
-rw-r--r-- | src/cow_http_hd.erl | 29 |
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. |