Author: markt
Date: Thu Nov 30 10:20:16 2017
New Revision: 1816698
URL: http://svn.apache.org/viewvc?rev=1816698&view=rev
Log:
Refactoring: HTTP/1.1 - HTTP/2 alignment
Add flush() to HttpOutputBuffer and chain filter implementations
Modified:
tomcat/trunk/java/org/apache/coyote/http11/Http11OutputBuffer.java
tomcat/trunk/java/org/apache/coyote/http11/HttpOutputBuffer.java
tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
tomcat/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java
tomcat/trunk/java/org/apache/coyote/http11/filters/IdentityOutputFilter.java
tomcat/trunk/java/org/apache/coyote/http11/filters/VoidOutputFilter.java
tomcat/trunk/test/org/apache/coyote/http11/filters/TesterOutputBuffer.java
Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11OutputBuffer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11OutputBuffer.java?rev=1816698&r1=1816697&r2=1816698&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11OutputBuffer.java
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11OutputBuffer.java Thu Nov
30 10:20:16 2017
@@ -210,32 +210,41 @@ public class Http11OutputBuffer implemen
}
- // --------------------------------------------------------- Public Methods
+ // ----------------------------------------------- HttpOutputBuffer Methods
/**
* Flush the response.
*
* @throws IOException an underlying I/O error occurred
*/
+ @Override
public void flush() throws IOException {
- // go through the filters and if there is gzip filter
- // invoke it to flush
- for (int i = 0; i <= lastActiveFilter; i++) {
- if (activeFilters[i] instanceof GzipOutputFilter) {
- if (log.isDebugEnabled()) {
- log.debug("Flushing the gzip filter at position " + i +
- " of the filter chain...");
- }
- ((GzipOutputFilter) activeFilters[i]).flush();
- break;
- }
+ if (lastActiveFilter == -1) {
+ outputStreamOutputBuffer.flush();
+ } else {
+ activeFilters[lastActiveFilter].flush();
+ }
+ }
+
+
+ @Override
+ public void end() throws IOException {
+ if (responseFinished) {
+ return;
}
- // Flush the current buffer(s)
- flushBuffer(isBlocking());
+ if (lastActiveFilter == -1) {
+ outputStreamOutputBuffer.end();
+ } else {
+ activeFilters[lastActiveFilter].end();
+ }
+
+ responseFinished = true;
}
+ // --------------------------------------------------------- Public Methods
+
/**
* Reset the header buffer if an error occurs during the writing of the
* headers so the error response can be written.
@@ -276,22 +285,6 @@ public class Http11OutputBuffer implemen
}
- @Override
- public void end() throws IOException {
- if (responseFinished) {
- return;
- }
-
- if (lastActiveFilter == -1) {
- outputStreamOutputBuffer.end();
- } else {
- activeFilters[lastActiveFilter].end();
- }
-
- responseFinished = true;
- }
-
-
public void init(SocketWrapperBase<?> socketWrapper) {
this.socketWrapper = socketWrapper;
}
@@ -563,5 +556,10 @@ public class Http11OutputBuffer implemen
public void end() throws IOException {
socketWrapper.flush(true);
}
+
+ @Override
+ public void flush() throws IOException {
+ socketWrapper.flush(isBlocking());
+ }
}
}
Modified: tomcat/trunk/java/org/apache/coyote/http11/HttpOutputBuffer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/HttpOutputBuffer.java?rev=1816698&r1=1816697&r2=1816698&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/HttpOutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/HttpOutputBuffer.java Thu Nov 30
10:20:16 2017
@@ -30,4 +30,11 @@ public interface HttpOutputBuffer extend
* @throws IOException If an I/O error occurs while writing to the client
*/
public void end() throws IOException;
+
+ /**
+ * Flushes any unwritten data to the client.
+ *
+ * @throws IOException If an I/O error occurs while flushing
+ */
+ public void flush() throws IOException;
}
Modified:
tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java?rev=1816698&r1=1816697&r2=1816698&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
Thu Nov 30 10:20:16 2017
@@ -152,6 +152,13 @@ public class ChunkedOutputFilter impleme
@Override
+ public void flush() throws IOException {
+ // No data buffered in this filter. Flush next buffer.
+ buffer.flush();
+ }
+
+
+ @Override
public void end() throws IOException {
Supplier<Map<String,String>> trailerFieldsSupplier =
response.getTrailerFields();
Modified:
tomcat/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java?rev=1816698&r1=1816697&r2=1816698&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java
Thu Nov 30 10:20:16 2017
@@ -87,7 +87,8 @@ public class GzipOutputFilter implements
/**
* Added to allow flushing to happen for the gzip'ed outputstream
*/
- public void flush() {
+ @Override
+ public void flush() throws IOException {
if (compressionStream != null) {
try {
if (log.isDebugEnabled()) {
@@ -100,6 +101,7 @@ public class GzipOutputFilter implements
}
}
}
+ buffer.flush();
}
Modified:
tomcat/trunk/java/org/apache/coyote/http11/filters/IdentityOutputFilter.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/IdentityOutputFilter.java?rev=1816698&r1=1816697&r2=1816698&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/coyote/http11/filters/IdentityOutputFilter.java
(original)
+++
tomcat/trunk/java/org/apache/coyote/http11/filters/IdentityOutputFilter.java
Thu Nov 30 10:20:16 2017
@@ -112,6 +112,13 @@ public class IdentityOutputFilter implem
@Override
+ public void flush() throws IOException {
+ // No data buffered in this filter. Flush next buffer.
+ buffer.flush();
+ }
+
+
+ @Override
public void end() throws IOException {
buffer.end();
}
Modified:
tomcat/trunk/java/org/apache/coyote/http11/filters/VoidOutputFilter.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/VoidOutputFilter.java?rev=1816698&r1=1816697&r2=1816698&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/filters/VoidOutputFilter.java
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/filters/VoidOutputFilter.java
Thu Nov 30 10:20:16 2017
@@ -60,6 +60,12 @@ public class VoidOutputFilter implements
@Override
+ public void flush() throws IOException {
+ // NO-OP
+ }
+
+
+ @Override
public void recycle() {
// NOOP: Nothing to recycle
}
Modified:
tomcat/trunk/test/org/apache/coyote/http11/filters/TesterOutputBuffer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/filters/TesterOutputBuffer.java?rev=1816698&r1=1816697&r2=1816698&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http11/filters/TesterOutputBuffer.java
(original)
+++ tomcat/trunk/test/org/apache/coyote/http11/filters/TesterOutputBuffer.java
Thu Nov 30 10:20:16 2017
@@ -114,6 +114,12 @@ public class TesterOutputBuffer extends
return byteCount;
}
+
+ @Override
+ public void flush() throws IOException {
+ // NO-OP: Unused
+ }
+
@Override
public void end() throws IOException {
// NO-OP: Unused
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]