Allow custom RSocket WebsocketServerSpecs to be defined
See gh-29567
This commit is contained in:
parent
b8e8b1d483
commit
f840141652
|
|
@ -73,6 +73,8 @@ public class RSocketProperties {
|
|||
@NestedConfigurationProperty
|
||||
private Ssl ssl;
|
||||
|
||||
private Spec spec = new Spec();
|
||||
|
||||
public Integer getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
|
@ -121,6 +123,72 @@ public class RSocketProperties {
|
|||
this.ssl = ssl;
|
||||
}
|
||||
|
||||
public Spec getSpec() {
|
||||
return this.spec;
|
||||
}
|
||||
|
||||
public void setSpec(Spec spec) {
|
||||
this.spec = spec;
|
||||
}
|
||||
|
||||
public static class Spec {
|
||||
|
||||
/**
|
||||
* Sub-protocol to use in websocket handshake signature.
|
||||
*/
|
||||
private String protocols;
|
||||
|
||||
/**
|
||||
* Specifies a custom maximum allowable frame payload length. 65536 by
|
||||
* default.
|
||||
*/
|
||||
private int maxFramePayloadLength = 65536;
|
||||
|
||||
/**
|
||||
* Flag whether to proxy websocket ping frames or respond to them.
|
||||
*/
|
||||
private boolean handlePing;
|
||||
|
||||
/**
|
||||
* Flag whether the websocket compression extension is enabled if the client
|
||||
* request presents websocket extensions headers.
|
||||
*/
|
||||
private boolean compress;
|
||||
|
||||
public String getProtocols() {
|
||||
return this.protocols;
|
||||
}
|
||||
|
||||
public void setProtocols(String protocols) {
|
||||
this.protocols = protocols;
|
||||
}
|
||||
|
||||
public int getMaxFramePayloadLength() {
|
||||
return this.maxFramePayloadLength;
|
||||
}
|
||||
|
||||
public void setMaxFramePayloadLength(int maxFramePayloadLength) {
|
||||
this.maxFramePayloadLength = maxFramePayloadLength;
|
||||
}
|
||||
|
||||
public boolean isHandlePing() {
|
||||
return this.handlePing;
|
||||
}
|
||||
|
||||
public void setHandlePing(boolean handlePing) {
|
||||
this.handlePing = handlePing;
|
||||
}
|
||||
|
||||
public boolean isCompress() {
|
||||
return this.compress;
|
||||
}
|
||||
|
||||
public void setCompress(boolean compress) {
|
||||
this.compress = compress;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class RSocketServerAutoConfiguration {
|
|||
RSocketWebSocketNettyRouteProvider rSocketWebsocketRouteProvider(RSocketProperties properties,
|
||||
RSocketMessageHandler messageHandler, ObjectProvider<RSocketServerCustomizer> customizers) {
|
||||
return new RSocketWebSocketNettyRouteProvider(properties.getServer().getMappingPath(),
|
||||
messageHandler.responder(), customizers.orderedStream());
|
||||
properties.getServer().getSpec(), messageHandler.responder(), customizers.orderedStream());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ import io.rsocket.core.RSocketServer;
|
|||
import io.rsocket.transport.ServerTransport;
|
||||
import io.rsocket.transport.netty.server.WebsocketRouteTransport;
|
||||
import reactor.netty.http.server.HttpServerRoutes;
|
||||
import reactor.netty.http.server.WebsocketServerSpec;
|
||||
|
||||
import org.springframework.boot.autoconfigure.rsocket.RSocketProperties.Server.Spec;
|
||||
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
|
||||
import org.springframework.boot.web.embedded.netty.NettyRouteProvider;
|
||||
|
||||
|
|
@ -32,6 +34,7 @@ import org.springframework.boot.web.embedded.netty.NettyRouteProvider;
|
|||
* {@link NettyRouteProvider} that configures an RSocket Websocket endpoint.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @author Leo Li
|
||||
*/
|
||||
class RSocketWebSocketNettyRouteProvider implements NettyRouteProvider {
|
||||
|
||||
|
|
@ -41,11 +44,14 @@ class RSocketWebSocketNettyRouteProvider implements NettyRouteProvider {
|
|||
|
||||
private final List<RSocketServerCustomizer> customizers;
|
||||
|
||||
RSocketWebSocketNettyRouteProvider(String mappingPath, SocketAcceptor socketAcceptor,
|
||||
private final Spec spec;
|
||||
|
||||
RSocketWebSocketNettyRouteProvider(String mappingPath, Spec spec, SocketAcceptor socketAcceptor,
|
||||
Stream<RSocketServerCustomizer> customizers) {
|
||||
this.mappingPath = mappingPath;
|
||||
this.socketAcceptor = socketAcceptor;
|
||||
this.customizers = customizers.toList();
|
||||
this.spec = spec;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -53,7 +59,11 @@ class RSocketWebSocketNettyRouteProvider implements NettyRouteProvider {
|
|||
RSocketServer server = RSocketServer.create(this.socketAcceptor);
|
||||
this.customizers.forEach((customizer) -> customizer.customize(server));
|
||||
ServerTransport.ConnectionAcceptor connectionAcceptor = server.asConnectionAcceptor();
|
||||
return httpServerRoutes.ws(this.mappingPath, WebsocketRouteTransport.newHandler(connectionAcceptor));
|
||||
WebsocketServerSpec.Builder build = (this.spec.getProtocols() == null) ? WebsocketServerSpec.builder()
|
||||
: WebsocketServerSpec.builder().protocols(this.spec.getProtocols());
|
||||
return httpServerRoutes.ws(this.mappingPath, WebsocketRouteTransport.newHandler(connectionAcceptor),
|
||||
build.maxFramePayloadLength(this.spec.getMaxFramePayloadLength()).handlePing(this.spec.isHandlePing())
|
||||
.compress(this.spec.isCompress()).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue