From 901a17d197fd9ab7f0bbcf01faf9969668a8ee7f Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 19 Nov 2020 10:24:36 -0600 Subject: [PATCH] Issue #5605 - Adding more comments Signed-off-by: Joakim Erdfelt --- .../jetty/test/GzipWithSendErrorTest.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/GzipWithSendErrorTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/GzipWithSendErrorTest.java index 291219e0d22..63f8f415d5a 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/GzipWithSendErrorTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/GzipWithSendErrorTest.java @@ -220,8 +220,15 @@ public class GzipWithSendErrorTest compressedRequest = out.toByteArray(); } + // We want to write a request with request body content size / length + // that will exceed the various buffers in the network, the client, the server, + // etc. int sizeActuallySent = compressedRequest.length / 2; ByteBuffer start = ByteBuffer.wrap(compressedRequest, 0, sizeActuallySent); + + // Using deferred content to allow us to write SOME of the request body content + // but not all of it (yet) + // We override the getLength to ensure that Content-Length is used. DeferredContentProvider contentProvider = new DeferredContentProvider(start) { @Override @@ -250,6 +257,7 @@ public class GzipWithSendErrorTest Response response = clientResponseRef.get(); assertEquals(400, response.getStatus(), "Response status on /fail"); + // We expect the server to set `Connection: close`, as the request body content isn't fully sent (yet) assertEquals("close", response.getHeaders().get(HttpHeader.CONNECTION), "Response Connection header"); // Await for server side to complete the request @@ -270,7 +278,7 @@ public class GzipWithSendErrorTest assertThat("Request Connection BytesIn should have some minimal data", inputBytesIn.get(), greaterThanOrEqualTo(1024L)); assertThat("Request Connection BytesIn read should not have read all of the data", inputBytesIn.get(), lessThanOrEqualTo((long)sizeActuallySent)); - // Now provide rest + // Now use the deferred content to complete writing of the request body content contentProvider.offer(ByteBuffer.wrap(compressedRequest, sizeActuallySent, compressedRequest.length - sizeActuallySent)); contentProvider.close(); @@ -334,8 +342,15 @@ public class GzipWithSendErrorTest compressedRequest = out.toByteArray(); } + // We want to write a request with request body content size / length + // that will exceed the various buffers in the network, the client, the server, + // etc. + int sizeActuallySent = compressedRequest.length / 2; ByteBuffer start = ByteBuffer.wrap(compressedRequest, 0, sizeActuallySent); + + // Using deferred content to allow us to write SOME of the request body content + // but not all of it (yet) DeferredContentProvider contentProvider = new DeferredContentProvider(start); AtomicReference clientResponseRef = new AtomicReference<>(); CountDownLatch clientResponseSuccessLatch = new CountDownLatch(1); @@ -359,6 +374,7 @@ public class GzipWithSendErrorTest Response response = clientResponseRef.get(); assertEquals(400, response.getStatus(), "Response status on /fail"); + // We expect the server to set `Connection: close`, as the request body content isn't fully sent (yet) assertEquals("close", response.getHeaders().get(HttpHeader.CONNECTION), "Response Connection header"); // Await for server side to complete the request @@ -381,7 +397,7 @@ public class GzipWithSendErrorTest assertThat("Request Connection BytesIn should have some minimal data", inputBytesIn.get(), greaterThanOrEqualTo(1024L)); assertThat("Request Connection BytesIn read should not have read all of the data", inputBytesIn.get(), lessThanOrEqualTo((long)sizeActuallySent)); - // Now provide rest + // Now use the deferred content to complete writing of the request body content contentProvider.offer(ByteBuffer.wrap(compressedRequest, sizeActuallySent, compressedRequest.length - sizeActuallySent)); contentProvider.close();