Hello, Since ring 1.11, what’s the idiomatic way of configuring ring-jetty websocket timeouts and max message size?
There's no common type of underlying socket, so my inclination is not to provide access via the websocket API. If someone wants to use an AsyncChannel directly, there's usually more low-level interfaces that would give them access to that.
Looks like it’s not possible to configure timeout and payload sizes per WS session. Because the Listener ring ws protocol do not expose the underlying Session or Remote.
In the meantime, I configured it globally with this:
(import 'org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer)
(defn configure-websocket! [server]
(JettyWebSocketServletContainerInitializer/configure
(.getHandler server)
(reify JettyWebSocketServletContainerInitializer$Configurator
(accept [_this _servletContext wsContainer]
(.setIdleTimeout wsContainer (java.time.Duration/ofSeconds 60))
#_(.setMaxBinaryMessageSize wsContainer 65535)
#_(.setMaxTextMessageSize wsContainer 65535)))))
(comment
(ring/run-jetty my-middleware {:port 8080 :configurator configure-websocket!}))Unfortunately not every Java websocket implementation supports message timeouts or max message sizes, and functionality may differ between implementations that do. Timeouts can be added with middleware, which means we don't have to worry about whether the underlying adapter supports it. Max message size is more tricky; while we can easily throw away messages with large message sizes, depending on the underlying implementation, they may still be loaded into memory. For Ring 1.12 I plan to investigate whether it's better to add a global but adapter-specific option to limit max message size, or to see if I can find some common denominator that works with all underlying implementations.
Make sense. Thank you for this comprehensive answer. Did you consider exposing the underlying socket (e.g. jetty's Session or httpkit's AsyncChannel) to the user, for advanced use cases?