Author: markt Date: Thu Oct 13 10:37:29 2016 New Revision: 1764649 URL: http://svn.apache.org/viewvc?rev=1764649&view=rev Log: Refactor header completion handling to a single method
Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java 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=1764649&r1=1764648&r2=1764649&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java (original) +++ tomcat/trunk/java/org/apache/coyote/http2/Http2Parser.java Thu Oct 13 10:37:29 2016 @@ -241,25 +241,17 @@ class Http2Parser { payloadSize -= padLength; } - boolean endOfHeaders = Flags.isEndOfHeaders(flags); - - readHeaderPayload(payloadSize, endOfHeaders); + readHeaderPayload(payloadSize); swallow(streamId, padLength, true); - if (endOfHeaders) { - output.headersEnd(streamId); + headersEndStream = Flags.isEndOfStream(flags); + + if (Flags.isEndOfHeaders(flags)) { + onHeadersComplete(streamId); } else { headersCurrentStream = streamId; } - - if (Flags.isEndOfStream(flags)) { - if (headersCurrentStream == -1) { - output.receiveEndOfStream(streamId); - } else { - headersEndStream = true; - } - } } @@ -377,22 +369,16 @@ class Http2Parser { Integer.toString(streamId)), Http2Error.PROTOCOL_ERROR); } - boolean endOfHeaders = Flags.isEndOfHeaders(flags); - readHeaderPayload(payloadSize, endOfHeaders); + readHeaderPayload(payloadSize); - if (endOfHeaders) { - output.headersEnd(streamId); + if (Flags.isEndOfHeaders(flags)) { + onHeadersComplete(streamId); headersCurrentStream = -1; - if (headersEndStream) { - output.receiveEndOfStream(streamId); - headersEndStream = false; - } } } - private void readHeaderPayload(int payloadSize, boolean endOfHeaders) - throws Http2Exception, IOException { + private void readHeaderPayload(int payloadSize) throws Http2Exception, IOException { while (payloadSize > 0) { int toRead = Math.min(headerReadBuffer.remaining(), payloadSize); @@ -411,12 +397,23 @@ class Http2Parser { headerReadBuffer.compact(); payloadSize -= toRead; } + } + - if (headerReadBuffer.position() > 0 && endOfHeaders) { + private void onHeadersComplete(int streamId) throws Http2Exception { + // Any left over data is a compression error + if (headerReadBuffer.position() > 0) { throw new ConnectionException( sm.getString("http2Parser.processFrameHeaders.decodingDataLeft"), Http2Error.COMPRESSION_ERROR); } + + output.headersEnd(streamId); + + if (headersEndStream) { + output.receiveEndOfStream(streamId); + headersEndStream = false; + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org