mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-19 09:38:02 +01:00
Extract configuration for WebSocket max message sizes
This commit is contained in:
@@ -23,6 +23,7 @@ import org.whispersystems.websocket.auth.AuthenticationException;
|
||||
import org.whispersystems.websocket.auth.WebSocketAuthenticator;
|
||||
import org.whispersystems.websocket.auth.WebSocketAuthenticator.AuthenticationResult;
|
||||
import org.whispersystems.websocket.auth.WebsocketAuthValueFactoryProvider;
|
||||
import org.whispersystems.websocket.configuration.WebSocketConfiguration;
|
||||
import org.whispersystems.websocket.session.WebSocketSessionContextValueFactoryProvider;
|
||||
import org.whispersystems.websocket.setup.WebSocketEnvironment;
|
||||
|
||||
@@ -31,9 +32,11 @@ public class WebSocketResourceProviderFactory<T extends Principal> extends WebSo
|
||||
private static final Logger logger = LoggerFactory.getLogger(WebSocketResourceProviderFactory.class);
|
||||
|
||||
private final WebSocketEnvironment<T> environment;
|
||||
private final ApplicationHandler jerseyApplicationHandler;
|
||||
private final ApplicationHandler jerseyApplicationHandler;
|
||||
private final WebSocketConfiguration configuration;
|
||||
|
||||
public WebSocketResourceProviderFactory(WebSocketEnvironment<T> environment, Class<T> principalClass) {
|
||||
public WebSocketResourceProviderFactory(WebSocketEnvironment<T> environment, Class<T> principalClass,
|
||||
WebSocketConfiguration configuration) {
|
||||
this.environment = environment;
|
||||
|
||||
environment.jersey().register(new WebSocketSessionContextValueFactoryProvider.Binder());
|
||||
@@ -41,6 +44,8 @@ public class WebSocketResourceProviderFactory<T extends Principal> extends WebSo
|
||||
environment.jersey().register(new JacksonMessageBodyProvider(environment.getObjectMapper()));
|
||||
|
||||
this.jerseyApplicationHandler = new ApplicationHandler(environment.jersey());
|
||||
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,9 +84,8 @@ public class WebSocketResourceProviderFactory<T extends Principal> extends WebSo
|
||||
@Override
|
||||
public void configure(WebSocketServletFactory factory) {
|
||||
factory.setCreator(this);
|
||||
// TODO extract to configuration
|
||||
factory.getPolicy().setMaxBinaryMessageSize(512 * 1024);
|
||||
factory.getPolicy().setMaxTextMessageSize(512 * 1024);
|
||||
factory.getPolicy().setMaxBinaryMessageSize(configuration.getMaxBinaryMessageSize());
|
||||
factory.getPolicy().setMaxTextMessageSize(configuration.getMaxTextMessageSize());
|
||||
}
|
||||
|
||||
private String getRemoteAddress(ServletUpgradeRequest request) {
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
package org.whispersystems.websocket.configuration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.whispersystems.websocket.logging.WebsocketRequestLoggerFactory;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.whispersystems.websocket.logging.WebsocketRequestLoggerFactory;
|
||||
|
||||
public class WebSocketConfiguration {
|
||||
|
||||
@@ -17,7 +18,25 @@ public class WebSocketConfiguration {
|
||||
@JsonProperty
|
||||
private WebsocketRequestLoggerFactory requestLog = new WebsocketRequestLoggerFactory();
|
||||
|
||||
@Min(512 * 1024) // 512 KB
|
||||
@Max(10 * 1024 * 1024) // 10 MB
|
||||
@JsonProperty
|
||||
private int maxBinaryMessageSize = 512 * 1024;
|
||||
|
||||
@Min(512 * 1024) // 512 KB
|
||||
@Max(10 * 1024 * 1024) // 10 MB
|
||||
@JsonProperty
|
||||
private int maxTextMessageSize = 512 * 1024;
|
||||
|
||||
public WebsocketRequestLoggerFactory getRequestLog() {
|
||||
return requestLog;
|
||||
}
|
||||
|
||||
public int getMaxBinaryMessageSize() {
|
||||
return maxBinaryMessageSize;
|
||||
}
|
||||
|
||||
public int getMaxTextMessageSize() {
|
||||
return maxTextMessageSize;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user