Skip to content

Commit

Permalink
Merge #2686 into 1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Feb 8, 2023
2 parents a80dba6 + 078686d commit dfb1e18
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,15 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
cookieEncoder,
formDecoderProvider,
httpMessageLogFactory,
true,
mapHandle,
secured,
timestamp);
}
catch (RuntimeException e) {
pendingResponse = false;
request.setDecoderResult(DecoderResult.failure(e.getCause() != null ? e.getCause() : e));
HttpServerOperations.sendDecodingFailures(ctx, listener, secured, e, msg, httpMessageLogFactory, timestamp);
HttpServerOperations.sendDecodingFailures(ctx, listener, secured, e, msg, httpMessageLogFactory, true, timestamp);
return;
}
ops.bind();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketCloseStatus;
import io.netty.handler.codec.http2.HttpConversionUtil;
import io.netty.util.AsciiString;
import io.netty.util.ReferenceCountUtil;
import org.reactivestreams.Publisher;
Expand Down Expand Up @@ -114,6 +113,7 @@ class HttpServerOperations extends HttpOperations<HttpServerRequest, HttpServerR
final ServerCookieEncoder cookieEncoder;
final ServerCookies cookieHolder;
final HttpServerFormDecoderProvider formDecoderProvider;
final boolean isHttp2;
final BiFunction<? super Mono<Void>, ? super Connection, ? extends Mono<Void>> mapHandle;
final HttpRequest nettyRequest;
final HttpResponse nettyResponse;
Expand All @@ -138,6 +138,7 @@ class HttpServerOperations extends HttpOperations<HttpServerRequest, HttpServerR
this.cookieHolder = replaced.cookieHolder;
this.currentContext = replaced.currentContext;
this.formDecoderProvider = replaced.formDecoderProvider;
this.isHttp2 = replaced.isHttp2;
this.mapHandle = replaced.mapHandle;
this.nettyRequest = replaced.nettyRequest;
this.nettyResponse = replaced.nettyResponse;
Expand All @@ -156,11 +157,12 @@ class HttpServerOperations extends HttpOperations<HttpServerRequest, HttpServerR
ServerCookieEncoder encoder,
HttpServerFormDecoderProvider formDecoderProvider,
HttpMessageLogFactory httpMessageLogFactory,
boolean isHttp2,
@Nullable BiFunction<? super Mono<Void>, ? super Connection, ? extends Mono<Void>> mapHandle,
boolean secured,
ZonedDateTime timestamp) {
this(c, listener, nettyRequest, compressionPredicate, connectionInfo, decoder, encoder, formDecoderProvider,
httpMessageLogFactory, mapHandle, true, secured, timestamp);
httpMessageLogFactory, isHttp2, mapHandle, true, secured, timestamp);
}

HttpServerOperations(Connection c, ConnectionObserver listener, HttpRequest nettyRequest,
Expand All @@ -170,6 +172,7 @@ class HttpServerOperations extends HttpOperations<HttpServerRequest, HttpServerR
ServerCookieEncoder encoder,
HttpServerFormDecoderProvider formDecoderProvider,
HttpMessageLogFactory httpMessageLogFactory,
boolean isHttp2,
@Nullable BiFunction<? super Mono<Void>, ? super Connection, ? extends Mono<Void>> mapHandle,
boolean resolvePath,
boolean secured,
Expand All @@ -183,6 +186,7 @@ class HttpServerOperations extends HttpOperations<HttpServerRequest, HttpServerR
this.cookieHolder = ServerCookies.newServerRequestHolder(nettyRequest.headers(), decoder);
this.currentContext = Context.empty();
this.formDecoderProvider = formDecoderProvider;
this.isHttp2 = isHttp2;
this.mapHandle = mapHandle;
this.nettyRequest = nettyRequest;
this.nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
Expand Down Expand Up @@ -344,7 +348,7 @@ public boolean isWebsocket() {
}

final boolean isHttp2() {
return requestHeaders().contains(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text());
return isHttp2;
}

@Override
Expand Down Expand Up @@ -777,6 +781,17 @@ static long requestsCounter(Channel channel) {
return ((AtomicLong) ops.connection()).get();
}

static void sendDecodingFailures(
ChannelHandlerContext ctx,
ConnectionObserver listener,
boolean secure,
Throwable t,
Object msg,
HttpMessageLogFactory httpMessageLogFactory,
@Nullable ZonedDateTime timestamp) {
sendDecodingFailures(ctx, listener, secure, t, msg, httpMessageLogFactory, false, timestamp);
}

@SuppressWarnings("FutureReturnValueIgnored")
static void sendDecodingFailures(
ChannelHandlerContext ctx,
Expand All @@ -785,6 +800,7 @@ static void sendDecodingFailures(
Throwable t,
Object msg,
HttpMessageLogFactory httpMessageLogFactory,
boolean isHttp2,
@Nullable ZonedDateTime timestamp) {

Throwable cause = t.getCause() != null ? t.getCause() : t;
Expand Down Expand Up @@ -816,8 +832,8 @@ else if (cause instanceof TooLongHttpHeaderException) {
if (ops == null) {
Connection conn = Connection.from(ctx.channel());
if (msg instanceof HttpRequest) {
ops = new FailedHttpServerRequest(conn, listener, (HttpRequest) msg, response, httpMessageLogFactory, secure,
timestamp == null ? ZonedDateTime.now(ReactorNetty.ZONE_ID_SYSTEM) : timestamp);
ops = new FailedHttpServerRequest(conn, listener, (HttpRequest) msg, response, httpMessageLogFactory, isHttp2,
secure, timestamp == null ? ZonedDateTime.now(ReactorNetty.ZONE_ID_SYSTEM) : timestamp);
ops.bind();
}
else {
Expand Down Expand Up @@ -986,10 +1002,11 @@ static final class FailedHttpServerRequest extends HttpServerOperations {
HttpRequest nettyRequest,
HttpResponse nettyResponse,
HttpMessageLogFactory httpMessageLogFactory,
boolean isHttp2,
boolean secure,
ZonedDateTime timestamp) {
super(c, listener, nettyRequest, null, null, ServerCookieDecoder.STRICT, ServerCookieEncoder.STRICT,
DEFAULT_FORM_DECODER_SPEC, httpMessageLogFactory, null, false, secure, timestamp);
DEFAULT_FORM_DECODER_SPEC, httpMessageLogFactory, isHttp2, null, false, secure, timestamp);
this.customResponse = nettyResponse;
String tempPath = "";
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
cookieEncoder,
formDecoderProvider,
httpMessageLogFactory,
false,
mapHandle,
secure,
timestamp);
Expand Down Expand Up @@ -414,6 +415,7 @@ public void run() {
cookieEncoder,
formDecoderProvider,
httpMessageLogFactory,
false,
mapHandle,
secure,
holder.timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,7 @@ private void doTestStatus(HttpResponseStatus status) {
ServerCookieEncoder.STRICT,
DEFAULT_FORM_DECODER_SPEC,
ReactorNettyHttpMessageLogFactory.INSTANCE,
false,
null,
false,
ZonedDateTime.now(ReactorNetty.ZONE_ID_SYSTEM));
Expand Down Expand Up @@ -2928,6 +2929,7 @@ private void doTestIsFormUrlencoded(String headerValue, boolean expectation) {
ServerCookieEncoder.STRICT,
DEFAULT_FORM_DECODER_SPEC,
ReactorNettyHttpMessageLogFactory.INSTANCE,
false,
null,
false,
ZonedDateTime.now(ReactorNetty.ZONE_ID_SYSTEM));
Expand Down

0 comments on commit dfb1e18

Please sign in to comment.