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

fix #1478 Schedule the first channel.read() once the HttpHeaders are sent #1480

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -197,7 +197,8 @@ public Mono<Void> then() {
throw e;
}

return channel().writeAndFlush(msg);
return channel().writeAndFlush(msg)
.addListener(f -> onHeadersSent());
}
else {
return channel().newSucceededFuture();
Expand All @@ -209,6 +210,8 @@ public Mono<Void> then() {

protected abstract void afterMarkSentHeaders();

protected abstract void onHeadersSent();

protected abstract HttpMessage newFullBodyMessage(ByteBuf body);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,14 @@ protected void beforeMarkSentHeaders() {
}
}

@Override
protected void onHeadersSent() {
channel().read();
if (channel().parent() != null) {
channel().parent().read();
}
}

@Override
@SuppressWarnings("FutureReturnValueIgnored")
protected void onOutboundComplete() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,11 @@ protected void beforeMarkSentHeaders() {
//noop
}

@Override
protected void onHeadersSent() {
//noop
}

@Override
protected void onOutboundComplete() {
if (isWebsocket()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.security.cert.CertificateException;
import java.time.Duration;
import java.util.ArrayList;
Expand Down Expand Up @@ -2552,4 +2554,39 @@ private void doTestEvictInBackground(int expectation, boolean evict) throws Exce
assertThat(m.get()).isNotNull();
assertThat(m.get().idleSize()).isEqualTo(expectation);
}

@Test
void testIssue1478() throws Exception {
disposableServer =
HttpServer.create()
.handle((req, res) -> res.addHeader(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE)
.status(HttpResponseStatus.BAD_REQUEST)
.send(req.receive()
.retain()
.next()))
.bindNow();

Path largeFile = Paths.get(getClass().getResource("/largeFile.txt").toURI());

Path largeFileParent = largeFile.getParent();
assertThat(largeFileParent).isNotNull();

Path tempFile = Files.createTempFile(largeFileParent, "temp", ".txt");
tempFile.toFile().deleteOnExit();

byte[] fileBytes = Files.readAllBytes(largeFile);
for (int i = 0; i < 1000; i++) {
Files.write(tempFile, fileBytes, StandardOpenOption.APPEND);
}

HttpClient.create()
.port(disposableServer.port())
.post()
.send((req, out) -> out.sendFile(tempFile))
.responseSingle((res, bytes) -> Mono.just(res.status().code()))
.as(StepVerifier::create)
.expectNext(400)
.expectComplete()
.verify(Duration.ofSeconds(5));
}
}