Polishing

See gh-28847
This commit is contained in:
rstoyanchev
2022-09-12 09:36:31 +01:00
parent 3a5f550a30
commit 3c5888c43f
3 changed files with 3 additions and 152 deletions

View File

@@ -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<String, String> adapter = new Netty5HeadersAdapter(response.responseHeaders());
this.headers = HttpHeaders.readOnlyHttpHeaders(adapter);
this.inbound = inbound;
this.bufferFactory = new Netty5DataBufferFactory(alloc);
}
@Override
public String getId() {

View File

@@ -53,9 +53,6 @@ public class ReactorNetty2WebSocketClient implements WebSocketClient {
private final Supplier<WebsocketClientSpec.Builder> 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.
* <p>Corresponds to the argument with the same name in the constructor of
* {@link io.netty5.handler.codec.http.websocketx.WebSocketServerHandshakerFactory
* WebSocketServerHandshakerFactory} in Netty.
* <p>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.
* <p>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<Void> execute(URI url, WebSocketHandler handler) {
@@ -189,9 +123,10 @@ public class ReactorNetty2WebSocketClient implements WebSocketClient {
@Override
public Mono<Void> 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);
}

View File

@@ -46,12 +46,6 @@ public class ReactorNetty2RequestUpgradeStrategy implements RequestUpgradeStrate
private final Supplier<WebsocketServerSpec.Builder> 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.
* <p>Corresponds to the argument with the same name in the constructor of
* {@link io.netty5.handler.codec.http.websocketx.WebSocketServerHandshakerFactory
* WebSocketServerHandshakerFactory} in Netty.
* <p>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.
* <p>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<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,