-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Websocket compression, disable 9.4 #1341
Comments
You can still do that, but only after the server has started. |
remove compression filter after server.start: jetty/jetty.project#1341
I moved the code after server.start(), but it doesn`t make a difference
My server init code is pretty basic, it is available here. |
I solved it; replaced configureContext with():
|
That is needlessly complicated. The WebSocketUpgradeFilter can be configured directly. // Server init code
WebSocketUpgradeFilter wsuf = WebSocketUpgradeFilter.configureContext(context);
wsuf.getFactory().getExtensionFactory().unregister("permessage-deflate"); or, from ... // Override this method, part of WebSocketHandler, or WebSocketServlet
public void configure(WebSocketServletFactory factory)
{
factory.getExtensionFactory().unregister("permessage-deflate");
} or, strip it from the upgrade request from the client ... // Override this method from WebSocketCreator
public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp)
{
List<ExtensionConfig> negotiated = new ArrayList<>();
for(ExtensionConfig config: req.getExtensions())
{
if (!config.getName().equals("permessage-deflate"))
{
negotiated.add(config);
}
}
resp.setExtensions(negotiated);
// rest of your create impl here
return endpoint;
} |
You can even register a public class AdjustWebSocket implements ServletContextListener
{
public void contextInitialized(ServletContextEvent sce)
{
NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) sce.getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName());
configuration.getFactory().getExtensionFactory().unregister("permessage-deflate");
}
public void contextDestroyed(ServletContextEvent sce)
{
}
} |
You can even use the JSR356 ServerEndpointConfig.Configurator to strip it from the client. public class NoExtensionsConfigurator extends ServerEndpointConfig.Configurator
{
@Override
public List<Extension> getNegotiatedExtensions(List<Extension> installed,
List<Extension> requested)
{
return Collections.emptyList();
}
} |
Wow, thanks! My init code, including ServerContainer changes is now: WebSocketUpgradeFilter wsuf = WebSocketUpgradeFilter.configureContext(context);
wsuf.getFactory().getExtensionFactory().unregister("permessage-deflate");
ServerContainer sc= new ServerContainer(wsuf.getConfiguration(), server.getThreadPool());
context.addBean(sc); |
Don't initialize the Why are you using JSR356? It's a very naive API, and your needs have already outgrown it (as evidenced by you need to configure things that are not exposed by the JSR356 API). Would encourage you to look at / use the Native WebSocket API in Jetty, as things get much simpler, and far more powerful (configurable). If you need to stick with JSR356, then use the |
Correct configuration of websocket compression. Compression is provided out of the box by Jetty's `permessage-deflate` extension. Previously Openfire was registering the `permessage-deflate` extension, I assume this was attempting to enable websocket compression. Presently, websocket compression is enabled by default in Jetty. So the correct way to control websocket compression is to disable the `permessage-deflate` extension when compression is not wanted: jetty/jetty.project#1341
Correct configuration of websocket compression. Compression is provided out of the box by Jetty's `permessage-deflate` extension. Previously Openfire was registering the `permessage-deflate` extension, I assume this was attempting to enable websocket compression. Presently, websocket compression is enabled by default in Jetty. So the correct way to control websocket compression is to disable the `permessage-deflate` extension when compression is not wanted: jetty/jetty.project#1341
Correct configuration of websocket compression. Compression is provided out of the box by Jetty's `permessage-deflate` extension. Previously Openfire was registering the `permessage-deflate` extension, I assume this was attempting to enable websocket compression. Presently, websocket compression is enabled by default in Jetty. So the correct way to control websocket compression is to disable the `permessage-deflate` extension when compression is not wanted: jetty/jetty.project#1341
I´d like to disable websocket compression to reduce cpu consumption.
In 9.3 it was possible via:
Is there a way to do this in jetty 9.4?
The text was updated successfully, but these errors were encountered: