From ea91c6ab4310abbe4de5eac6db66db6fafac32d1 Mon Sep 17 00:00:00 2001 From: Adam Kalisz Date: Tue, 18 May 2021 23:00:25 +0200 Subject: [PATCH] Add support for websocket-connection options The use-case is e.g. if you want to send larger WS messages. The max-frame-payload is 65536 bytes and max-frame-size is 1048576 bytes by default. It seems, the disassembly/ reassembly of frames isn't supported in some scenarios but there is still need for larger data transfer over WS. Therefore the easiest solution is to just increase the max-frame-payload size. Aleph currently has 7 options to configure more appropriate settings in less common circumstances. If no map of options is provided, the code works as before and is therefore to the best of my knowledge backwards compatible. --- src/taoensso/sente/server_adapters/aleph.clj | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/taoensso/sente/server_adapters/aleph.clj b/src/taoensso/sente/server_adapters/aleph.clj index 5b681bc6..61fdf36f 100644 --- a/src/taoensso/sente/server_adapters/aleph.clj +++ b/src/taoensso/sente/server_adapters/aleph.clj @@ -24,13 +24,13 @@ (when-let [s (get-in ring-req [:headers "upgrade"])] (= "websocket" (str/lower-case s)))) -(deftype AlephAsyncNetworkChannelAdapter [] +(deftype AlephAsyncNetworkChannelAdapter [options] i/IServerChanAdapter (ring-req->server-ch-resp [sch-adapter ring-req callbacks-map] (let [{:keys [on-open on-close on-msg _on-error]} callbacks-map ws? (websocket-req? ring-req)] (if ws? - (d/chain (aleph/websocket-connection ring-req) + (d/chain (aleph/websocket-connection ring-req options) (fn [s] ; sch (when on-msg (s/consume (fn [msg] (on-msg s ws? msg)) s)) (when on-close (s/on-closed s (fn [] (on-close s ws? nil)))) @@ -41,4 +41,8 @@ (when on-open (do (on-open s ws?))) {:body s}))))) -(defn get-sch-adapter [] (AlephAsyncNetworkChannelAdapter.)) +(defn get-sch-adapter + "Supports websocket-connection options in aleph.http. If no option map is provided, + the default options apply." + ([] (AlephAsyncNetworkChannelAdapter. nil)) + ([options] (AlephAsyncNetworkChannelAdapter. options)))