aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAli Sabil <[email protected]>2013-07-02 10:58:12 +0200
committerAli Sabil <[email protected]>2013-07-02 10:58:12 +0200
commit4edef3c45c70051dc5e8d49a1308e86b73be6e8f (patch)
tree950dce73207e7d77ba746c4640ab442719c80bc3 /src
parent39caf34fe3bc0a3c89ac8a06428542555f8e13c1 (diff)
downloadcowboy-4edef3c45c70051dc5e8d49a1308e86b73be6e8f.tar.gz
cowboy-4edef3c45c70051dc5e8d49a1308e86b73be6e8f.tar.bz2
cowboy-4edef3c45c70051dc5e8d49a1308e86b73be6e8f.zip
Remove usage of the inflate buffer
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_websocket.erl21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl
index df50162..c9220f0 100644
--- a/src/cowboy_websocket.erl
+++ b/src/cowboy_websocket.erl
@@ -57,9 +57,8 @@
frag_state = undefined :: frag_state(),
utf8_state = <<>> :: binary(),
deflate_frame = false :: boolean(),
- inflate_state :: any(),
- inflate_buffer = <<>> :: binary(),
- deflate_state :: any()
+ inflate_state :: undefined | port(),
+ deflate_state :: undefined | port()
}).
%% @doc Upgrade an HTTP request to the Websocket protocol.
@@ -121,7 +120,6 @@ websocket_extensions(State, Req) ->
{ok, State#state{
deflate_frame = true,
inflate_state = Inflate,
- inflate_buffer = <<>>,
deflate_state = Deflate
}, Req2};
_ ->
@@ -450,14 +448,13 @@ websocket_inflate_frame(Data, << Rsv1:1, _:2 >>, _,
#state{deflate_frame = DeflateFrame} = State)
when DeflateFrame =:= false orelse Rsv1 =:= 0 ->
{Data, State};
-websocket_inflate_frame(Data, << 1:1, _:2 >>, false,
- #state{inflate_buffer = Buffer} = State) ->
- {<<>>, State#state{inflate_buffer = << Buffer/binary, Data/binary >>}};
-websocket_inflate_frame(Data, << 1:1, _:2 >>, true,
- #state{inflate_state = Inflate, inflate_buffer = Buffer} = State) ->
- Deflated = << Buffer/binary, Data/binary, 0:8, 0:8, 255:8, 255:8 >>,
- Result = zlib:inflate(Inflate, Deflated),
- {iolist_to_binary(Result), State#state{inflate_buffer = <<>>}}.
+websocket_inflate_frame(Data, << 1:1, _:2 >>, false, State) ->
+ Result = zlib:inflate(State#state.inflate_state, Data),
+ {iolist_to_binary(Result), State};
+websocket_inflate_frame(Data, << 1:1, _:2 >>, true, State) ->
+ Result = zlib:inflate(State#state.inflate_state,
+ << Data/binary, 0:8, 0:8, 255:8, 255:8 >>),
+ {iolist_to_binary(Result), State}.
-spec websocket_unmask(B, mask_key(), B) -> B when B::binary().
websocket_unmask(<<>>, _, Unmasked) ->