You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/03/07 11:46:07 UTC

[tomcat] branch 8.5.x updated: Align HTTP/2 code with master to simplify back-ports

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

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


The following commit(s) were added to refs/heads/8.5.x by this push:
     new 4c782c5  Align HTTP/2 code with master to simplify back-ports
4c782c5 is described below

commit 4c782c59e5f21e16810237f8ff22813821bbe53a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Mar 7 11:45:39 2019 +0000

    Align HTTP/2 code with master to simplify back-ports
---
 .../apache/coyote/http2/Http2UpgradeHandler.java   | 87 +++++++++++++---------
 1 file changed, 50 insertions(+), 37 deletions(-)

diff --git a/java/org/apache/coyote/http2/Http2UpgradeHandler.java b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
index 6e266c3..8e45d4f 100644
--- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java
+++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
@@ -558,6 +558,22 @@ public class Http2UpgradeHandler extends AbstractStream implements InternalHttpU
 
     void writeHeaders(Stream stream, int pushedStreamId, MimeHeaders mimeHeaders,
             boolean endOfStream, int payloadSize) throws IOException {
+        // This ensures the Stream processing thread has control of the socket.
+        synchronized (socketWrapper) {
+            doWriteHeaders(stream, pushedStreamId, mimeHeaders, endOfStream, payloadSize);
+        }
+        if (endOfStream) {
+            stream.sentEndOfStream();
+        }
+    }
+
+
+    /*
+     * Separate method to allow Http2AsyncUpgradeHandler to call this code
+     * without synchronizing on socketWrapper since it doesn't need to.
+     */
+    protected void doWriteHeaders(Stream stream, int pushedStreamId,
+            MimeHeaders mimeHeaders, boolean endOfStream, int payloadSize) throws IOException {
 
         if (log.isDebugEnabled()) {
             if (pushedStreamId == 0) {
@@ -586,47 +602,44 @@ public class Http2UpgradeHandler extends AbstractStream implements InternalHttpU
         boolean first = true;
         State state = null;
 
-        // This ensures the Stream processing thread has control of the socket.
-        synchronized (socketWrapper) {
-            while (state != State.COMPLETE) {
-                if (first && pushedStreamIdBytes != null) {
-                    payload.put(pushedStreamIdBytes);
-                }
-                state = getHpackEncoder().encode(mimeHeaders, payload);
-                payload.flip();
-                if (state == State.COMPLETE || payload.limit() > 0) {
-                    ByteUtil.setThreeBytes(header, 0, payload.limit());
-                    if (first) {
-                        first = false;
-                        if (pushedStreamIdBytes == null) {
-                            header[3] = FrameType.HEADERS.getIdByte();
-                        } else {
-                            header[3] = FrameType.PUSH_PROMISE.getIdByte();
-                        }
-                        if (endOfStream) {
-                            header[4] = FLAG_END_OF_STREAM;
-                        }
+        while (state != State.COMPLETE) {
+            if (first && pushedStreamIdBytes != null) {
+                payload.put(pushedStreamIdBytes);
+            }
+            state = getHpackEncoder().encode(mimeHeaders, payload);
+            payload.flip();
+            if (state == State.COMPLETE || payload.limit() > 0) {
+                ByteUtil.setThreeBytes(header, 0, payload.limit());
+                if (first) {
+                    first = false;
+                    if (pushedStreamIdBytes == null) {
+                        header[3] = FrameType.HEADERS.getIdByte();
                     } else {
-                        header[3] = FrameType.CONTINUATION.getIdByte();
-                    }
-                    if (state == State.COMPLETE) {
-                        header[4] += FLAG_END_OF_HEADERS;
-                    }
-                    if (log.isDebugEnabled()) {
-                        log.debug(payload.limit() + " bytes");
+                        header[3] = FrameType.PUSH_PROMISE.getIdByte();
                     }
-                    ByteUtil.set31Bits(header, 5, stream.getIdAsInt());
-                    try {
-                        socketWrapper.write(true, header, 0, header.length);
-                        socketWrapper.write(true, payload);
-                        socketWrapper.flush(true);
-                    } catch (IOException ioe) {
-                        handleAppInitiatedIOException(ioe);
+                    if (endOfStream) {
+                        header[4] = FLAG_END_OF_STREAM;
                     }
-                    payload.clear();
-                } else if (state == State.UNDERFLOW) {
-                    payload = ByteBuffer.allocate(payload.capacity() * 2);
+                } else {
+                    header[3] = FrameType.CONTINUATION.getIdByte();
+                }
+                if (state == State.COMPLETE) {
+                    header[4] += FLAG_END_OF_HEADERS;
+                }
+                if (log.isDebugEnabled()) {
+                    log.debug(payload.limit() + " bytes");
+                }
+                ByteUtil.set31Bits(header, 5, stream.getIdAsInt());
+                try {
+                    socketWrapper.write(true, header, 0, header.length);
+                    socketWrapper.write(true, payload);
+                    socketWrapper.flush(true);
+                } catch (IOException ioe) {
+                    handleAppInitiatedIOException(ioe);
                 }
+                payload.clear();
+            } else if (state == State.UNDERFLOW) {
+                payload = ByteBuffer.allocate(payload.capacity() * 2);
             }
         }
     }


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