aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-10-05 16:40:29 +0200
committerLoïc Hoguin <[email protected]>2019-10-05 16:40:29 +0200
commitfaa57b16eba29a2609c23bbe01d42f6d37a1d511 (patch)
tree5b8c979e1f33ff09b15b3e136c3f2d1b01e9f441
parent3d163136e59ed02719fe6dd5f57bbcd7a82d6fef (diff)
downloadcowlib-faa57b16eba29a2609c23bbe01d42f6d37a1d511.tar.gz
cowlib-faa57b16eba29a2609c23bbe01d42f6d37a1d511.tar.bz2
cowlib-faa57b16eba29a2609c23bbe01d42f6d37a1d511.zip
Allow disabling the UTF-8 Websocket text frames validation
-rw-r--r--src/cow_ws.erl10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/cow_ws.erl b/src/cow_ws.erl
index d24dc12..3bb46c5 100644
--- a/src/cow_ws.erl
+++ b/src/cow_ws.erl
@@ -69,7 +69,7 @@
-type rsv() :: <<_:3>>.
-export_type([rsv/0]).
--type utf8_state() :: 0..8.
+-type utf8_state() :: 0..8 | undefined.
-export_type([utf8_state/0]).
%% @doc Generate a key for the Websocket handshake request.
@@ -466,7 +466,8 @@ parse_payload(Data, MaskKey, Utf8State, ParsedLen, Type, Len, FragState,
Payload = inflate_frame(unmask(Data2, MaskKey, ParsedLen), Inflate, TakeOver, FragState, Eof),
validate_payload(Payload, Rest, Utf8State, ParsedLen, Type, FragState, Eof);
%% Empty frame.
-parse_payload(Data, _, Utf8State = 0, 0, _, 0, _, _, _) ->
+parse_payload(Data, _, Utf8State, 0, _, 0, _, _, _)
+ when Utf8State =:= 0; Utf8State =:= undefined ->
{ok, <<>>, Utf8State, Data};
%% Start of close frame.
parse_payload(Data, MaskKey, Utf8State, 0, Type = close, Len, FragState, _, << 0:3 >>) ->
@@ -551,6 +552,11 @@ inflate_frame(Data, Inflate, TakeOver, FragState, true)
inflate_frame(Data, Inflate, _T, _F, _E) ->
iolist_to_binary(zlib:inflate(Inflate, Data)).
+%% The Utf8State variable can be set to 'undefined' to disable the validation.
+validate_payload(Payload, _, undefined, _, _, _, false) ->
+ {more, Payload, undefined};
+validate_payload(Payload, Rest, undefined, _, _, _, true) ->
+ {ok, Payload, undefined, Rest};
%% Text frames and close control frames MUST have a payload that is valid UTF-8.
validate_payload(Payload, Rest, Utf8State, _, Type, _, Eof) when Type =:= text; Type =:= close ->
case validate_utf8(Payload, Utf8State) of