This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 55e79890bfc392a4e7c1312f250cba64896cd48f
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Sep 30 11:49:48 2024 +0100

    Refactor HTTP/2 trailer testing to create trailers separately
    
    This will allow other requests to be multiplexed between the headers and
    trailers of the stream using trailers.
---
 test/org/apache/coyote/http2/Http2TestBase.java     | 21 +++++++++++----------
 .../apache/coyote/http2/TestAsyncReadListener.java  |  3 ++-
 .../apache/coyote/http2/TestCancelledUpload.java    |  4 ++--
 .../apache/coyote/http2/TestHttp2AccessLogs.java    |  3 ++-
 test/org/apache/coyote/http2/TestHttp2Limits.java   |  4 ++--
 .../apache/coyote/http2/TestHttp2Section_8_1.java   |  6 +++---
 test/org/apache/coyote/http2/TestHttpServlet.java   |  2 +-
 test/org/apache/coyote/http2/TestLargeUpload.java   |  4 ++--
 8 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/test/org/apache/coyote/http2/Http2TestBase.java 
b/test/org/apache/coyote/http2/Http2TestBase.java
index dc9c22cb34..e9d3a5de81 100644
--- a/test/org/apache/coyote/http2/Http2TestBase.java
+++ b/test/org/apache/coyote/http2/Http2TestBase.java
@@ -348,7 +348,7 @@ public abstract class Http2TestBase extends TomcatBaseTest {
         ByteBuffer dataPayload = ByteBuffer.allocate(128);
 
         buildPostRequest(headersFrameHeader, headersPayload, useExpectation, 
"application/x-www-form-urlencoded",
-                contentLength, "/parameter", dataFrameHeader, dataPayload, 
padding, null, null, streamId);
+                contentLength, "/parameter", dataFrameHeader, dataPayload, 
padding, false, streamId);
         writeFrame(headersFrameHeader, headersPayload);
         if (body != null) {
             dataPayload.put(body.getBytes(StandardCharsets.ISO_8859_1));
@@ -360,19 +360,18 @@ public abstract class Http2TestBase extends 
TomcatBaseTest {
     protected void buildPostRequest(byte[] headersFrameHeader, ByteBuffer 
headersPayload, boolean useExpectation,
             byte[] dataFrameHeader, ByteBuffer dataPayload, byte[] padding, 
int streamId) {
         buildPostRequest(headersFrameHeader, headersPayload, useExpectation, 
dataFrameHeader, dataPayload, padding,
-                null, null, streamId);
+                false, streamId);
     }
 
     protected void buildPostRequest(byte[] headersFrameHeader, ByteBuffer 
headersPayload, boolean useExpectation,
-            byte[] dataFrameHeader, ByteBuffer dataPayload, byte[] padding, 
byte[] trailersFrameHeader,
-            ByteBuffer trailersPayload, int streamId) {
+            byte[] dataFrameHeader, ByteBuffer dataPayload, byte[] padding, 
boolean withTrailers, int streamId) {
         buildPostRequest(headersFrameHeader, headersPayload, useExpectation, 
null, -1, "/simple", dataFrameHeader,
-                dataPayload, padding, trailersFrameHeader, trailersPayload, 
streamId);
+                dataPayload, padding, withTrailers, streamId);
     }
 
     protected void buildPostRequest(byte[] headersFrameHeader, ByteBuffer 
headersPayload, boolean useExpectation,
             String contentType, long contentLength, String path, byte[] 
dataFrameHeader, ByteBuffer dataPayload,
-            byte[] padding, byte[] trailersFrameHeader, ByteBuffer 
trailersPayload, int streamId) {
+            byte[] padding, boolean withTrailers, int streamId) {
 
         MimeHeaders headers = new MimeHeaders();
         headers.addValue(":method").setString("POST");
@@ -419,17 +418,19 @@ public abstract class Http2TestBase extends 
TomcatBaseTest {
         ByteUtil.setThreeBytes(dataFrameHeader, 0, dataPayload.limit());
         // Data is type 0
         // Flags: End of stream 1, Padding 8
-        if (trailersPayload == null) {
-            dataFrameHeader[4] = 0x01;
-        } else {
+        if (withTrailers) {
             dataFrameHeader[4] = 0x00;
+        } else {
+            dataFrameHeader[4] = 0x01;
         }
         if (padding != null) {
             dataFrameHeader[4] += 0x08;
         }
         ByteUtil.set31Bits(dataFrameHeader, 5, streamId);
+    }
+
 
-        // Trailers
+    protected void buildTrailerHeaders(byte[] trailersFrameHeader, ByteBuffer 
trailersPayload, int streamId) {
         if (trailersPayload != null) {
             MimeHeaders trailerHeaders = new MimeHeaders();
             
trailerHeaders.addValue(TRAILER_HEADER_NAME).setString(TRAILER_HEADER_VALUE);
diff --git a/test/org/apache/coyote/http2/TestAsyncReadListener.java 
b/test/org/apache/coyote/http2/TestAsyncReadListener.java
index 2c02223770..614e487b46 100644
--- a/test/org/apache/coyote/http2/TestAsyncReadListener.java
+++ b/test/org/apache/coyote/http2/TestAsyncReadListener.java
@@ -77,7 +77,8 @@ public class TestAsyncReadListener extends Http2TestBase {
 
 
         buildPostRequest(headersFrameHeader, headersPayload, false, null, -1, 
"/async", dataFrameHeader, dataPayload,
-            null, trailerFrameHeader, trailerPayload, 3);
+            null, true, 3);
+        buildTrailerHeaders(trailerFrameHeader, trailerPayload, 3);
 
         synchronized (asyncServlet) {
             // Write the headers
diff --git a/test/org/apache/coyote/http2/TestCancelledUpload.java 
b/test/org/apache/coyote/http2/TestCancelledUpload.java
index 75ceeb96cd..ed317f27bd 100644
--- a/test/org/apache/coyote/http2/TestCancelledUpload.java
+++ b/test/org/apache/coyote/http2/TestCancelledUpload.java
@@ -50,8 +50,8 @@ public class TestCancelledUpload extends Http2TestBase {
         byte[] trailerFrameHeader = new byte[9];
         ByteBuffer trailerPayload = ByteBuffer.allocate(256);
 
-        buildPostRequest(headersFrameHeader, headersPayload, false, 
dataFrameHeader, dataPayload, null,
-                trailerFrameHeader, trailerPayload, 3);
+        buildPostRequest(headersFrameHeader, headersPayload, false, 
dataFrameHeader, dataPayload, null, true, 3);
+        buildTrailerHeaders(trailerFrameHeader, trailerPayload, 3);
 
         // Write the headers
         writeFrame(headersFrameHeader, headersPayload);
diff --git a/test/org/apache/coyote/http2/TestHttp2AccessLogs.java 
b/test/org/apache/coyote/http2/TestHttp2AccessLogs.java
index ae9a9b5ace..ef397d4166 100644
--- a/test/org/apache/coyote/http2/TestHttp2AccessLogs.java
+++ b/test/org/apache/coyote/http2/TestHttp2AccessLogs.java
@@ -92,7 +92,8 @@ public class TestHttp2AccessLogs extends Http2TestBase {
         ByteBuffer trailerPayload = ByteBuffer.allocate(256);
 
         buildPostRequest(headersFrameHeader, headersPayload, false, null, -1, 
"/trailers", dataFrameHeader, dataPayload,
-                null, trailerFrameHeader, trailerPayload, 3);
+                null, true, 3);
+        buildTrailerHeaders(trailerFrameHeader, trailerPayload, 3);
 
         // Write the headers
         writeFrame(headersFrameHeader, headersPayload);
diff --git a/test/org/apache/coyote/http2/TestHttp2Limits.java 
b/test/org/apache/coyote/http2/TestHttp2Limits.java
index b184270dc3..312e0c2289 100644
--- a/test/org/apache/coyote/http2/TestHttp2Limits.java
+++ b/test/org/apache/coyote/http2/TestHttp2Limits.java
@@ -499,8 +499,8 @@ public class TestHttp2Limits extends Http2TestBase {
         byte[] trailerFrameHeader = new byte[9];
         ByteBuffer trailerPayload = ByteBuffer.allocate(256);
 
-        buildPostRequest(headersFrameHeader, headersPayload, false, 
dataFrameHeader, dataPayload, null,
-                trailerFrameHeader, trailerPayload, 3);
+        buildPostRequest(headersFrameHeader, headersPayload, false, 
dataFrameHeader, dataPayload, null, true, 3);
+        buildTrailerHeaders(trailerFrameHeader, trailerPayload, 3);
 
         // Write the headers
         writeFrame(headersFrameHeader, headersPayload);
diff --git a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java 
b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java
index 5bc3e3872e..278f266474 100644
--- a/test/org/apache/coyote/http2/TestHttp2Section_8_1.java
+++ b/test/org/apache/coyote/http2/TestHttp2Section_8_1.java
@@ -63,8 +63,8 @@ public class TestHttp2Section_8_1 extends Http2TestBase {
         byte[] trailerFrameHeader = new byte[9];
         ByteBuffer trailerPayload = ByteBuffer.allocate(256);
 
-        buildPostRequest(headersFrameHeader, headersPayload, false, 
dataFrameHeader, dataPayload, null,
-                trailerFrameHeader, trailerPayload, 3);
+        buildPostRequest(headersFrameHeader, headersPayload, false, 
dataFrameHeader, dataPayload, null, true, 3);
+        buildTrailerHeaders(trailerFrameHeader, trailerPayload, 3);
 
         // Write the headers
         writeFrame(headersFrameHeader, headersPayload);
@@ -138,7 +138,7 @@ public class TestHttp2Section_8_1 extends Http2TestBase {
         ByteBuffer dataPayload = ByteBuffer.allocate(256);
 
         buildPostRequest(headersFrameHeader, headersPayload, true, null, -1, 
"/simple", dataFrameHeader, dataPayload,
-                null, null, null, 3);
+                null, false, 3);
 
         // Write the headers
         writeFrame(headersFrameHeader, headersPayload);
diff --git a/test/org/apache/coyote/http2/TestHttpServlet.java 
b/test/org/apache/coyote/http2/TestHttpServlet.java
index de3749cd48..0eaab65270 100644
--- a/test/org/apache/coyote/http2/TestHttpServlet.java
+++ b/test/org/apache/coyote/http2/TestHttpServlet.java
@@ -38,7 +38,7 @@ public class TestHttpServlet extends Http2TestBase {
         ByteBuffer dataPayload = ByteBuffer.allocate(0);
 
         buildPostRequest(headersFrameHeader, headersPayload, false, null, -1, 
"/empty", dataFrameHeader, dataPayload,
-                null, null, null, 3);
+                null, false, 3);
 
         // Write the headers
         writeFrame(headersFrameHeader, headersPayload);
diff --git a/test/org/apache/coyote/http2/TestLargeUpload.java 
b/test/org/apache/coyote/http2/TestLargeUpload.java
index 33da9b5879..ad509baa42 100644
--- a/test/org/apache/coyote/http2/TestLargeUpload.java
+++ b/test/org/apache/coyote/http2/TestLargeUpload.java
@@ -92,8 +92,8 @@ public class TestLargeUpload extends Http2TestBase {
         byte[] trailerFrameHeader = new byte[9];
         ByteBuffer trailerPayload = ByteBuffer.allocate(256);
 
-        buildPostRequest(headersFrameHeader, headersPayload, false, 
dataFrameHeader, dataPayload, null,
-                trailerFrameHeader, trailerPayload, 3);
+        buildPostRequest(headersFrameHeader, headersPayload, false, 
dataFrameHeader, dataPayload, null, true, 3);
+        buildTrailerHeaders(trailerFrameHeader, trailerPayload, 3);
 
         // Write the headers
         writeFrame(headersFrameHeader, headersPayload);


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to