svn commit: r1823896 - in /tomcat/trunk/java/org/apache/coyote/http2: Http2AsyncParser.java Http2Parser.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1823896 - in /tomcat/trunk/java/org/apache/coyote/http2: Http2AsyncParser.java Http2Parser.java

remm
Author: remm
Date: Sun Feb 11 20:57:37 2018
New Revision: 1823896

URL: http://svn.apache.org/viewvc?rev=1823896&view=rev
Log:
Add a flag for header parsing, and other cosmetic changes to trigger a build (TestHttp2Section_6_8 may be an intermittent failure on CI, although it works for me locally).

Modified:
    tomcat/trunk/java/org/apache/coyote/http2/Http2AsyncParser.java
    tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java

Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2AsyncParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Http2AsyncParser.java?rev=1823896&r1=1823895&r2=1823896&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/Http2AsyncParser.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http2/Http2AsyncParser.java Sun Feb 11 20:57:37 2018
@@ -30,8 +30,8 @@ import org.apache.tomcat.util.net.Socket
 
 class Http2AsyncParser extends Http2Parser {
 
-    protected final SocketWrapperBase<?> socketWrapper;
-    protected final Http2AsyncUpgradeHandler upgradeHandler;
+    private final SocketWrapperBase<?> socketWrapper;
+    private final Http2AsyncUpgradeHandler upgradeHandler;
     private Throwable error = null;
 
     Http2AsyncParser(String connectionId, Input input, Output output, SocketWrapperBase<?> socketWrapper, Http2AsyncUpgradeHandler upgradeHandler) {
@@ -79,7 +79,7 @@ class Http2AsyncParser extends Http2Pars
         }
     }
 
-    protected void unRead(ByteBuffer buffer) {
+    private void unRead(ByteBuffer buffer) {
         if (buffer != null && buffer.hasRemaining()) {
             socketWrapper.unRead(buffer);
         }
@@ -118,25 +118,31 @@ class Http2AsyncParser extends Http2Pars
     }
 
 
-    protected class FrameCompletionCheck implements CompletionCheck {
-        final FrameCompletionHandler handler;
-        boolean validated = false;
-        protected FrameCompletionCheck(FrameCompletionHandler handler) {
+    private class FrameCompletionCheck implements CompletionCheck {
+
+        private final FrameCompletionHandler handler;
+        private boolean parsedFrameHeader = false;
+        private boolean validated = false;
+
+        private FrameCompletionCheck(FrameCompletionHandler handler) {
             this.handler = handler;
         }
+
         @Override
         public CompletionHandlerCall callHandler(CompletionState state,
                 ByteBuffer[] buffers, int offset, int length) {
-            // The first buffer should be 9 bytes long
-            ByteBuffer frameHeaderBuffer = buffers[offset];
-            if (frameHeaderBuffer.position() < 9) {
-                return CompletionHandlerCall.CONTINUE;
+            if (!parsedFrameHeader) {
+                // The first buffer should be 9 bytes long
+                ByteBuffer frameHeaderBuffer = buffers[offset];
+                if (frameHeaderBuffer.position() < 9) {
+                    return CompletionHandlerCall.CONTINUE;
+                }
+                parsedFrameHeader = true;
+                handler.payloadSize = ByteUtil.getThreeBytes(frameHeaderBuffer, 0);
+                handler.frameType = FrameType.valueOf(ByteUtil.getOneByte(frameHeaderBuffer, 3));
+                handler.flags = ByteUtil.getOneByte(frameHeaderBuffer, 4);
+                handler.streamId = ByteUtil.get31Bits(frameHeaderBuffer, 5);
             }
-
-            handler.payloadSize = ByteUtil.getThreeBytes(frameHeaderBuffer, 0);
-            handler.frameType = FrameType.valueOf(ByteUtil.getOneByte(frameHeaderBuffer, 3));
-            handler.flags = ByteUtil.getOneByte(frameHeaderBuffer, 4);
-            handler.streamId = ByteUtil.get31Bits(frameHeaderBuffer, 5);
             handler.state = state;
 
             if (!validated) {
@@ -167,7 +173,8 @@ class Http2AsyncParser extends Http2Pars
 
     }
 
-    protected class FrameCompletionHandler implements CompletionHandler<Long, Void> {
+    private class FrameCompletionHandler implements CompletionHandler<Long, Void> {
+
         private final FrameType expected;
         private final ByteBuffer[] buffers;
         private int payloadSize;
@@ -177,7 +184,7 @@ class Http2AsyncParser extends Http2Pars
         private boolean streamException = false;
         private CompletionState state = null;
 
-        protected FrameCompletionHandler(FrameType expected, ByteBuffer... buffers) {
+        private FrameCompletionHandler(FrameType expected, ByteBuffer... buffers) {
             this.expected = expected;
             this.buffers = buffers;
         }
@@ -240,6 +247,7 @@ class Http2AsyncParser extends Http2Pars
 
         @Override
         public void failed(Throwable e, Void attachment) {
+            // Always a fatal IO error
             error = e;
             if (state == null || state == CompletionState.DONE) {
                 upgradeHandler.upgradeDispatch(SocketEvent.ERROR);

Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java?rev=1823896&r1=1823895&r2=1823896&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java Sun Feb 11 20:57:37 2018
@@ -32,19 +32,19 @@ class Http2Parser {
     protected static final Log log = LogFactory.getLog(Http2Parser.class);
     protected static final StringManager sm = StringManager.getManager(Http2Parser.class);
 
-    static final byte[] CLIENT_PREFACE_START =
+    private static final byte[] CLIENT_PREFACE_START =
             "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".getBytes(StandardCharsets.ISO_8859_1);
 
     protected final String connectionId;
     protected final Input input;
-    protected final Output output;
-    protected final byte[] frameHeaderBuffer = new byte[9];
+    private final Output output;
+    private final byte[] frameHeaderBuffer = new byte[9];
 
-    protected volatile HpackDecoder hpackDecoder;
-    protected volatile ByteBuffer headerReadBuffer =
+    private volatile HpackDecoder hpackDecoder;
+    private volatile ByteBuffer headerReadBuffer =
             ByteBuffer.allocate(Constants.DEFAULT_HEADER_READ_BUFFER_SIZE);
-    protected volatile int headersCurrentStream = -1;
-    protected volatile boolean headersEndStream = false;
+    private volatile int headersCurrentStream = -1;
+    private volatile boolean headersEndStream = false;
 
     Http2Parser(String connectionId, Input input, Output output) {
         this.connectionId = connectionId;



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]