aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-10-31 22:41:29 +0000
committerLoïc Hoguin <[email protected]>2017-10-31 22:42:36 +0000
commit1bdac844111eb11f584e38d1203882ec460d0201 (patch)
treed3f3a86bb334eeb632d068a2db76ceb68dc0cfdd
parentbd37be4d3b065600c3b76b492535e76e5d413fc1 (diff)
downloadcowlib-1bdac844111eb11f584e38d1203882ec460d0201.tar.gz
cowlib-1bdac844111eb11f584e38d1203882ec460d0201.tar.bz2
cowlib-1bdac844111eb11f584e38d1203882ec460d0201.zip
Fix Websocket compression for OTP 20.1.3+
This issue only concerns zlib contexts that are created in a different process from the one they are used in. Unfortunately compression will have to remain disabled if you are using OTP 20.1, 20.1.1 or 20.1.2 due to missing functionality. If you need compression you will need to use another version.
-rw-r--r--src/cow_ws.erl17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/cow_ws.erl b/src/cow_ws.erl
index bf315eb..a4b7933 100644
--- a/src/cow_ws.erl
+++ b/src/cow_ws.erl
@@ -151,12 +151,27 @@ init_permessage_deflate(InflateWindowBits, DeflateWindowBits, Opts) ->
maps:get(mem_level, Opts, 8),
maps:get(strategy, Opts, default)),
%% Set the owner pid of the zlib contexts if requested.
+ %%
+ %% The zlib port became a reference in OTP 20.1+. There
+ %% was however no way to change the controlling process
+ %% until the OTP 20.1.3 patch version. Since we can't
+ %% enable compression for 20.1, 20.1.1 and 20.1.2 we
+ %% explicitly crash. The caller should ignore this extension.
_ = case Opts of
- #{owner := Pid} ->
+ #{owner := Pid} when is_port(Inflate) ->
true = erlang:port_connect(Inflate, Pid),
true = unlink(Inflate),
true = erlang:port_connect(Deflate, Pid),
unlink(Deflate);
+ #{owner := Pid} ->
+ case erlang:function_exported(zlib, set_controlling_process, 2) of
+ true ->
+ zlib:set_controlling_process(Inflate, Pid),
+ zlib:set_controlling_process(Deflate, Pid);
+ false ->
+ exit({error, incompatible_zlib_version,
+ 'OTP 20.1, 20.1.1 and 20.1.2 are missing required functionality.'})
+ end;
_ ->
true
end,