From 3c5888c43f20ec61e3f3db49cc115b0b3a6304b2 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Mon, 12 Sep 2022 09:36:31 +0100 Subject: [PATCH] Polishing See gh-28847 --- .../ReactorNetty2ClientHttpResponse.java | 14 ---- .../client/ReactorNetty2WebSocketClient.java | 71 +------------------ .../ReactorNetty2RequestUpgradeStrategy.java | 70 ------------------ 3 files changed, 3 insertions(+), 152 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java index f697b0be44..a12d25944a 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java @@ -20,7 +20,6 @@ import java.util.Collection; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiFunction; -import io.netty5.buffer.api.BufferAllocator; import io.netty5.handler.codec.http.cookie.Cookie; import io.netty5.handler.codec.http.cookie.DefaultCookie; import org.apache.commons.logging.Log; @@ -80,19 +79,6 @@ class ReactorNetty2ClientHttpResponse implements ClientHttpResponse { this.bufferFactory = new Netty5DataBufferFactory(connection.outbound().alloc()); } - /** - * Constructor with inputs extracted from a {@link Connection}. - * @deprecated as of 5.2.8, in favor of {@link #ReactorNetty2ClientHttpResponse(HttpClientResponse, Connection)} - */ - @Deprecated - public ReactorNetty2ClientHttpResponse(HttpClientResponse response, NettyInbound inbound, BufferAllocator alloc) { - this.response = response; - MultiValueMap adapter = new Netty5HeadersAdapter(response.responseHeaders()); - this.headers = HttpHeaders.readOnlyHttpHeaders(adapter); - this.inbound = inbound; - this.bufferFactory = new Netty5DataBufferFactory(alloc); - } - @Override public String getId() { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNetty2WebSocketClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNetty2WebSocketClient.java index f169953a4e..4678e9213b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNetty2WebSocketClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNetty2WebSocketClient.java @@ -53,9 +53,6 @@ public class ReactorNetty2WebSocketClient implements WebSocketClient { private final Supplier specBuilderSupplier; - @Nullable - private Integer maxFramePayloadLength; - @Nullable private Boolean handlePing; @@ -114,72 +111,9 @@ public class ReactorNetty2WebSocketClient implements WebSocketClient { if (StringUtils.hasText(protocols)) { builder.protocols(protocols); } - if (this.maxFramePayloadLength != null) { - builder.maxFramePayloadLength(this.maxFramePayloadLength); - } - if (this.handlePing != null) { - builder.handlePing(this.handlePing); - } return builder.build(); } - /** - * Configure the maximum allowable frame payload length. Setting this value - * to your application's requirement may reduce denial of service attacks - * using long data frames. - *

Corresponds to the argument with the same name in the constructor of - * {@link io.netty5.handler.codec.http.websocketx.WebSocketServerHandshakerFactory - * WebSocketServerHandshakerFactory} in Netty. - *

By default set to 65536 (64K). - * @param maxFramePayloadLength the max length for frames. - * @since 5.2 - * @deprecated as of 5.3 in favor of providing a supplier of - * {@link WebsocketClientSpec.Builder} with a - * constructor argument - */ - @Deprecated - public void setMaxFramePayloadLength(int maxFramePayloadLength) { - this.maxFramePayloadLength = maxFramePayloadLength; - } - - /** - * Return the configured {@link #setMaxFramePayloadLength(int) maxFramePayloadLength}. - * @since 5.2 - * @deprecated as of 5.3 in favor of {@link #getWebsocketClientSpec()} - */ - @Deprecated - public int getMaxFramePayloadLength() { - return getWebsocketClientSpec().maxFramePayloadLength(); - } - - /** - * Configure whether to let ping frames through to be handled by the - * {@link WebSocketHandler} given to the execute method. By default, Reactor - * Netty automatically replies with pong frames in response to pings. This is - * useful in a proxy for allowing ping and pong frames through. - *

By default this is set to {@code false} in which case ping frames are - * handled automatically by Reactor Netty. If set to {@code true}, ping - * frames will be passed through to the {@link WebSocketHandler}. - * @param handlePing whether to let Ping frames through for handling - * @since 5.2.4 - * @deprecated as of 5.3 in favor of providing a supplier of - * {@link WebsocketClientSpec.Builder} with a - * constructor argument - */ - @Deprecated - public void setHandlePing(boolean handlePing) { - this.handlePing = handlePing; - } - - /** - * Return the configured {@link #setHandlePing(boolean)}. - * @since 5.2.4 - * @deprecated as of 5.3 in favor of {@link #getWebsocketClientSpec()} - */ - @Deprecated - public boolean getHandlePing() { - return getWebsocketClientSpec().handlePing(); - } @Override public Mono execute(URI url, WebSocketHandler handler) { @@ -189,9 +123,10 @@ public class ReactorNetty2WebSocketClient implements WebSocketClient { @Override public Mono execute(URI url, HttpHeaders requestHeaders, WebSocketHandler handler) { String protocols = StringUtils.collectionToCommaDelimitedString(handler.getSubProtocols()); + WebsocketClientSpec clientSpec = buildSpec(protocols); return getHttpClient() .headers(nettyHeaders -> setNettyHeaders(requestHeaders, nettyHeaders)) - .websocket(buildSpec(protocols)) + .websocket(clientSpec) .uri(url.toString()) .handle((inbound, outbound) -> { HttpHeaders responseHeaders = toHttpHeaders(inbound); @@ -199,7 +134,7 @@ public class ReactorNetty2WebSocketClient implements WebSocketClient { HandshakeInfo info = new HandshakeInfo(url, responseHeaders, Mono.empty(), protocol); Netty5DataBufferFactory factory = new Netty5DataBufferFactory(outbound.alloc()); WebSocketSession session = new ReactorNetty2WebSocketSession( - inbound, outbound, info, factory, getMaxFramePayloadLength()); + inbound, outbound, info, factory, clientSpec.maxFramePayloadLength()); if (logger.isDebugEnabled()) { logger.debug("Started session '" + session.getId() + "' for " + url); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNetty2RequestUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNetty2RequestUpgradeStrategy.java index 9670d093dc..14623902a5 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNetty2RequestUpgradeStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNetty2RequestUpgradeStrategy.java @@ -46,12 +46,6 @@ public class ReactorNetty2RequestUpgradeStrategy implements RequestUpgradeStrate private final Supplier specBuilderSupplier; - @Nullable - private Integer maxFramePayloadLength; - - @Nullable - private Boolean handlePing; - /** * Create an instances with a default {@link WebsocketServerSpec.Builder}. @@ -89,73 +83,9 @@ public class ReactorNetty2RequestUpgradeStrategy implements RequestUpgradeStrate if (subProtocol != null) { builder.protocols(subProtocol); } - if (this.maxFramePayloadLength != null) { - builder.maxFramePayloadLength(this.maxFramePayloadLength); - } - if (this.handlePing != null) { - builder.handlePing(this.handlePing); - } return builder.build(); } - /** - * Configure the maximum allowable frame payload length. Setting this value - * to your application's requirement may reduce denial of service attacks - * using long data frames. - *

Corresponds to the argument with the same name in the constructor of - * {@link io.netty5.handler.codec.http.websocketx.WebSocketServerHandshakerFactory - * WebSocketServerHandshakerFactory} in Netty. - *

By default set to 65536 (64K). - * @param maxFramePayloadLength the max length for frames. - * @since 5.1 - * @deprecated as of 5.2.6 in favor of providing a supplier of - * {@link WebsocketServerSpec.Builder} with a - * constructor argument - */ - @Deprecated - public void setMaxFramePayloadLength(Integer maxFramePayloadLength) { - this.maxFramePayloadLength = maxFramePayloadLength; - } - - /** - * Return the configured max length for frames. - * @since 5.1 - * @deprecated as of 5.2.6 in favor of {@link #getWebsocketServerSpec()} - */ - @Deprecated - public int getMaxFramePayloadLength() { - return getWebsocketServerSpec().maxFramePayloadLength(); - } - - /** - * Configure whether to let ping frames through to be handled by the - * {@link WebSocketHandler} given to the upgrade method. By default, Reactor - * Netty automatically replies with pong frames in response to pings. This is - * useful in a proxy for allowing ping and pong frames through. - *

By default this is set to {@code false} in which case ping frames are - * handled automatically by Reactor Netty. If set to {@code true}, ping - * frames will be passed through to the {@link WebSocketHandler}. - * @param handlePing whether to let Ping frames through for handling - * @since 5.2.4 - * @deprecated as of 5.2.6 in favor of providing a supplier of - * {@link WebsocketServerSpec.Builder} with a - * constructor argument - */ - @Deprecated - public void setHandlePing(boolean handlePing) { - this.handlePing = handlePing; - } - - /** - * Return the configured {@link #setHandlePing(boolean)}. - * @since 5.2.4 - * @deprecated as of 5.2.6 in favor of {@link #getWebsocketServerSpec()} - */ - @Deprecated - public boolean getHandlePing() { - return getWebsocketServerSpec().handlePing(); - } - @Override public Mono upgrade(ServerWebExchange exchange, WebSocketHandler handler,