Author: markt Date: Thu Nov 30 10:20:39 2017 New Revision: 1816702 URL: http://svn.apache.org/viewvc?rev=1816702&view=rev Log: Refactoring: HTTP/1.1 - HTTP/2 alignment
Add the Http2OutputBuffer which will be the insertion point for the GZip filter. Added: tomcat/trunk/java/org/apache/coyote/http2/Http2OutputBuffer.java (with props) Modified: tomcat/trunk/java/org/apache/coyote/http2/Stream.java tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java Added: tomcat/trunk/java/org/apache/coyote/http2/Http2OutputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Http2OutputBuffer.java?rev=1816702&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/Http2OutputBuffer.java (added) +++ tomcat/trunk/java/org/apache/coyote/http2/Http2OutputBuffer.java Thu Nov 30 10:20:39 2017 @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.coyote.http2; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.apache.coyote.http.HttpOutputBuffer; +import org.apache.coyote.http11.OutputFilter; +import org.apache.coyote.http2.Stream.StreamOutputBuffer; + +public class Http2OutputBuffer implements HttpOutputBuffer { + + private HttpOutputBuffer next; + + + /** + * Add a filter at the start of the existing processing chain. Subsequent + * calls to the {@link HttpOutputBuffer} methods of this object will be + * passed to the filter. If appropriate, the filter will then call the same + * method on the next HttpOutputBuffer in the chain until the call reaches + * the StreamOutputBuffer. + * + * @param filter The filter to add to the start of the processing chain + */ + public void addFilter(OutputFilter filter) { + filter.setBuffer(next); + next = filter; + } + + + public Http2OutputBuffer(StreamOutputBuffer streamOutputBuffer) { + this.next = streamOutputBuffer; + } + + + @Override + public int doWrite(ByteBuffer chunk) throws IOException { + return next.doWrite(chunk); + } + + + @Override + public long getBytesWritten() { + return next.getBytesWritten(); + } + + + @Override + public void end() throws IOException { + next.end(); + } + + + @Override + public void flush() throws IOException { + next.flush(); + } +} Propchange: tomcat/trunk/java/org/apache/coyote/http2/Http2OutputBuffer.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/java/org/apache/coyote/http2/Stream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Stream.java?rev=1816702&r1=1816701&r2=1816702&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/Stream.java (original) +++ tomcat/trunk/java/org/apache/coyote/http2/Stream.java Thu Nov 30 10:20:39 2017 @@ -75,7 +75,8 @@ class Stream extends AbstractStream impl private StringBuilder cookieHeader = null; private final Response coyoteResponse = new Response(); private final StreamInputBuffer inputBuffer; - private final StreamOutputBuffer outputBuffer = new StreamOutputBuffer(); + private final StreamOutputBuffer streamOutputBuffer = new StreamOutputBuffer(); + private final Http2OutputBuffer http2OutputBuffer = new Http2OutputBuffer(streamOutputBuffer); Stream(Integer identifier, Http2UpgradeHandler handler) { @@ -104,7 +105,7 @@ class Stream extends AbstractStream impl state.receivedEndOfStream(); } this.coyoteRequest.setSendfile(handler.hasAsyncIO() && handler.getProtocol().getUseSendfile()); - this.coyoteResponse.setOutputBuffer(outputBuffer); + this.coyoteResponse.setOutputBuffer(http2OutputBuffer); this.coyoteRequest.setResponse(coyoteResponse); this.coyoteRequest.protocol().setString("HTTP/2.0"); if (this.coyoteRequest.getStartTime() < 0) { @@ -406,7 +407,7 @@ class Stream extends AbstractStream impl final void writeHeaders() throws IOException { - boolean endOfStream = getOutputBuffer().hasNoBody() && + boolean endOfStream = streamOutputBuffer.hasNoBody() && coyoteResponse.getTrailerFields() == null; // TODO: Is 1k the optimal value? handler.writeHeaders(this, 0, coyoteResponse.getMimeHeaders(), endOfStream, 1024); @@ -525,18 +526,28 @@ class Stream extends AbstractStream impl final void sentEndOfStream() { - outputBuffer.endOfStreamSent = true; + streamOutputBuffer.endOfStreamSent = true; state.sentEndOfStream(); } + final boolean isReady() { + return streamOutputBuffer.isReady(); + } + + + final boolean flush(boolean block) throws IOException { + return streamOutputBuffer.flush(block); + } + + final StreamInputBuffer getInputBuffer() { return inputBuffer; } - final StreamOutputBuffer getOutputBuffer() { - return outputBuffer; + final HttpOutputBuffer getOutputBuffer() { + return http2OutputBuffer; } @@ -632,7 +643,7 @@ class Stream extends AbstractStream impl boolean isTrailerFieldsSupported() { - return !getOutputBuffer().endOfStreamSent; + return !streamOutputBuffer.endOfStreamSent; } Modified: tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java?rev=1816702&r1=1816701&r2=1816702&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java (original) +++ tomcat/trunk/java/org/apache/coyote/http2/StreamProcessor.java Thu Nov 30 10:20:39 2017 @@ -236,7 +236,7 @@ class StreamProcessor extends AbstractPr @Override protected final boolean isReady() { - return stream.getOutputBuffer().isReady(); + return stream.isReady(); } @@ -336,7 +336,7 @@ class StreamProcessor extends AbstractPr @Override protected final boolean flushBufferedWrite() throws IOException { - if (stream.getOutputBuffer().flush(false)) { + if (stream.flush(false)) { // The buffer wasn't fully flushed so re-register the // stream for write. Note this does not go via the // Response since the write registration state at @@ -344,7 +344,7 @@ class StreamProcessor extends AbstractPr // has been emptied then the code below will call // dispatch() which will enable the // Response to respond to this event. - if (stream.getOutputBuffer().isReady()) { + if (stream.isReady()) { // Unexpected throw new IllegalStateException(); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org