Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpServerRequest::receiveContent() never emits any value nor completes when HTTP/1.1 TLS Upgrade (RFC-2817) kicks in #3540

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,10 @@ else if (msg instanceof HttpRequest) {
}
else {
request.release();
// HTTP/1.1 TLS Upgrade (RFC-2817) on empty requests (GET/HEAD/OPTIONS)
reta marked this conversation as resolved.
Show resolved Hide resolved
if (!isHttp2() && request.headers().contains(HttpHeaderNames.UPGRADE)) {
onInboundComplete();
reta marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (isHttp2()) {
//force auto read to enable more accurate close selection now inbound is done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import io.netty.handler.codec.compression.Brotli;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpContentDecompressor;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
Expand All @@ -82,6 +83,7 @@
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
Expand All @@ -101,7 +103,10 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;

import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxSink;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Sinks;
import reactor.netty.BaseHttpTest;
Expand Down Expand Up @@ -1662,6 +1667,37 @@ void testIssue632() throws Exception {
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
}

@Test
void testIssue3538() throws Exception {
disposableServer =
createServer()
.protocol(HttpProtocol.H2C, HttpProtocol.HTTP11)
.route(r -> r.get("/", (req, res) -> {
final EchoAction action = new EchoAction();

req
.receiveContent().switchIfEmpty(Mono.just(LastHttpContent.EMPTY_LAST_CONTENT))
.subscribe(action);

return res.sendObject(action);
}
))
.bindNow();
assertThat(disposableServer).isNotNull();

final ByteBuf content = createHttpClientForContextWithPort()
.protocol(HttpProtocol.HTTP11)
.headers(h ->
h.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
.add(HttpHeaderNames.UPGRADE, "TLS/1.2"))
.get()
.uri("/")
.responseContent()
.blockLast(Duration.ofSeconds(30));

assertThat(content).isNull();
}

@Test
void testIssue694() {
disposableServer =
Expand Down Expand Up @@ -3513,4 +3549,29 @@ void testDeleteMethod(boolean chunked) {
.expectComplete()
.verify(Duration.ofSeconds(5));
}

private static class EchoAction implements Publisher<HttpContent>, Consumer<HttpContent> {
private final Publisher<HttpContent> sender;
private volatile FluxSink<HttpContent> emitter;

EchoAction() {
this.sender = Flux.create(emitter -> this.emitter = emitter);
}

@Override
public void accept(HttpContent message) {
if (message instanceof LastHttpContent) {
emitter.complete();
}
else {
emitter.next(message.retain());
}
}

@Override
public void subscribe(Subscriber<? super HttpContent> s) {
sender.subscribe(s);
}

}
}
Loading