[tomcat] 02/02: Simplify the closing of an HTTP/2 stream with an error condition

2021-03-12 Thread markt
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

commit 3c42ca9fe2263d507660a989ab65d5ba4f060cd5
Author: Mark Thomas 
AuthorDate: Fri Mar 12 12:12:41 2021 +

Simplify the closing of an HTTP/2 stream with an error condition
---
 java/org/apache/coyote/http2/StreamProcessor.java | 33 +++
 webapps/docs/changelog.xml|  4 +++
 2 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/java/org/apache/coyote/http2/StreamProcessor.java 
b/java/org/apache/coyote/http2/StreamProcessor.java
index 7690380..95af082 100644
--- a/java/org/apache/coyote/http2/StreamProcessor.java
+++ b/java/org/apache/coyote/http2/StreamProcessor.java
@@ -74,7 +74,16 @@ class StreamProcessor extends AbstractProcessor {
 
handler.getProtocol().getHttp11Protocol().addWaitingProcessor(this);
 } else if (state == SocketState.CLOSED) {
 
handler.getProtocol().getHttp11Protocol().removeWaitingProcessor(this);
-if (!getErrorState().isConnectionIoAllowed()) {
+if (!stream.isInputFinished() && 
getErrorState().isIoAllowed()) {
+// The request has been processed but the request 
body has not been
+// fully read. This typically occurs when Tomcat 
rejects an upload
+// of some form (e.g. PUT or POST). Need to tell 
the client not to
+// send any more data on this stream (reset).
+StreamException se = new StreamException(
+sm.getString("streamProcessor.cancel", 
stream.getConnectionId(),
+stream.getIdAsString()), 
Http2Error.CANCEL, stream.getIdAsInt());
+stream.close(se);
+} else if (!getErrorState().isConnectionIoAllowed()) {
 ConnectionException ce = new 
ConnectionException(sm.getString(
 "streamProcessor.error.connection", 
stream.getConnectionId(),
 stream.getIdAsString()), 
Http2Error.INTERNAL_ERROR);
@@ -373,13 +382,6 @@ class StreamProcessor extends AbstractProcessor {
 setErrorState(ErrorState.CLOSE_NOW, e);
 }
 
-if (!isAsync()) {
-// If this is an async request then the request ends when it has
-// been completed. The AsyncContext is responsible for calling
-// endRequest() in that case.
-endRequest();
-}
-
 if (getErrorState().isError()) {
 action(ActionCode.CLOSE, null);
 request.updateCounters();
@@ -420,21 +422,6 @@ class StreamProcessor extends AbstractProcessor {
 
 @Override
 protected final SocketState dispatchEndRequest() throws IOException {
-endRequest();
 return SocketState.CLOSED;
 }
-
-
-private void endRequest() {
-if (!stream.isInputFinished() && getErrorState().isIoAllowed()) {
-// The request has been processed but the request body has not been
-// fully read. This typically occurs when Tomcat rejects an upload
-// of some form (e.g. PUT or POST). Need to tell the client not to
-// send any more data on this stream (reset).
-StreamException se = new StreamException(
-sm.getString("streamProcessor.cancel", 
stream.getConnectionId(),
-stream.getIdAsString()), Http2Error.CANCEL, 
stream.getIdAsInt());
-stream.close(se);
-}
-}
 }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 69ccd4b..2be4fd4 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -119,6 +119,10 @@
 to recycle an HTTP/2 stream may result in
 NullPointerExceptions. (markt)
   
+  
+Simplify the closing on an HTTP/2 stream when an error condition is
+present. (markt)
+  
 
   
 


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



[tomcat] 02/02: Simplify the closing of an HTTP/2 stream with an error condition

2021-03-12 Thread markt
This is an automated email from the ASF dual-hosted git repository.

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

commit b16ffe56dd3238bdd91139f4a05116375b2b3d05
Author: Mark Thomas 
AuthorDate: Fri Mar 12 12:12:41 2021 +

Simplify the closing of an HTTP/2 stream with an error condition
---
 java/org/apache/coyote/http2/StreamProcessor.java | 41 ++-
 webapps/docs/changelog.xml|  4 +++
 2 files changed, 14 insertions(+), 31 deletions(-)

diff --git a/java/org/apache/coyote/http2/StreamProcessor.java 
b/java/org/apache/coyote/http2/StreamProcessor.java
index 2e757eb..d1ae2f9 100644
--- a/java/org/apache/coyote/http2/StreamProcessor.java
+++ b/java/org/apache/coyote/http2/StreamProcessor.java
@@ -77,7 +77,16 @@ class StreamProcessor extends AbstractProcessor {
 
handler.getProtocol().getHttp11Protocol().addWaitingProcessor(this);
 } else if (state == SocketState.CLOSED) {
 
handler.getProtocol().getHttp11Protocol().removeWaitingProcessor(this);
-if (!getErrorState().isConnectionIoAllowed()) {
+if (!stream.isInputFinished() && 
getErrorState().isIoAllowed()) {
+// The request has been processed but the request 
body has not been
+// fully read. This typically occurs when Tomcat 
rejects an upload
+// of some form (e.g. PUT or POST). Need to tell 
the client not to
+// send any more data on this stream (reset).
+StreamException se = new StreamException(
+sm.getString("streamProcessor.cancel", 
stream.getConnectionId(),
+stream.getIdAsString()), 
Http2Error.CANCEL, stream.getIdAsInt());
+stream.close(se);
+} else if (!getErrorState().isConnectionIoAllowed()) {
 ConnectionException ce = new 
ConnectionException(sm.getString(
 "streamProcessor.error.connection", 
stream.getConnectionId(),
 stream.getIdAsString()), 
Http2Error.INTERNAL_ERROR);
@@ -410,13 +419,6 @@ class StreamProcessor extends AbstractProcessor {
 setErrorState(ErrorState.CLOSE_NOW, e);
 }
 
-if (!isAsync()) {
-// If this is an async request then the request ends when it has
-// been completed. The AsyncContext is responsible for calling
-// endRequest() in that case.
-endRequest();
-}
-
 if (sendfileState == SendfileState.PENDING) {
 return SocketState.SENDFILE;
 } else if (getErrorState().isError()) {
@@ -459,29 +461,6 @@ class StreamProcessor extends AbstractProcessor {
 
 @Override
 protected final SocketState dispatchEndRequest() throws IOException {
-endRequest();
 return SocketState.CLOSED;
 }
-
-
-private void endRequest() {
-if (!stream.isInputFinished() && getErrorState().isIoAllowed()) {
-if (handler.hasAsyncIO() && !stream.isContentLengthInconsistent()) 
{
-// Need an additional checks for asyncIO as the end of stream
-// might have been set on the header frame but not processed
-// yet. Checking for this here so the extra processing only
-// occurs on the potential error condition rather than on every
-// request.
-return;
-}
-// The request has been processed but the request body has not been
-// fully read. This typically occurs when Tomcat rejects an upload
-// of some form (e.g. PUT or POST). Need to tell the client not to
-// send any more data on this stream (reset).
-StreamException se = new StreamException(
-sm.getString("streamProcessor.cancel", 
stream.getConnectionId(),
-stream.getIdAsString()), Http2Error.CANCEL, 
stream.getIdAsInt());
-stream.close(se);
-}
-}
 }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index e31899e..8135161 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -115,6 +115,10 @@
 to recycle an HTTP/2 stream may result in
 NullPointerExceptions. (markt)
   
+  
+Simplify the closing on an HTTP/2 stream when an error condition is
+present. (markt)
+  
 
   
 


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



[tomcat] 02/02: Simplify / align(ish) with 8.5.x.

2019-09-09 Thread markt
This is an automated email from the ASF dual-hosted git repository.

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

commit fa34afd8bb57ce73fd7cb4c1ae2b0379cb0bc001
Author: Mark Thomas 
AuthorDate: Mon Sep 9 13:00:02 2019 +0100

Simplify / align(ish) with 8.5.x.
---
 java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java 
b/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
index d6ef494..9d5f8ae 100644
--- a/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
+++ b/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
@@ -105,14 +105,14 @@ public class ChunkedOutputFilter implements OutputFilter {
 }
 
 // Calculate chunk header
-int pos = 7;
+int pos = 8;
 int current = result;
 while (current > 0) {
 int digit = current % 16;
 current = current / 16;
-chunkLength[pos--] = HexUtils.getHex(digit);
+chunkLength[--pos] = HexUtils.getHex(digit);
 }
-chunkHeader.setBytes(chunkLength, pos + 1, 9 - pos);
+chunkHeader.setBytes(chunkLength, pos, 10 - pos);
 buffer.doWrite(chunkHeader, res);
 
 buffer.doWrite(chunk, res);


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



[tomcat] 02/02: Simplify

2019-09-09 Thread markt
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

commit 096bb8d5347611099ba3a68f133a8e82b37dd28c
Author: Mark Thomas 
AuthorDate: Mon Sep 9 11:40:09 2019 +0100

Simplify

In calculateChunkHeader() start pos at 8 rather than 7 and then
decrement before it is used rather than after. This results in the same
number of decrement calls and the same values used in chunkHeader.put()
but the returned value is 1 higher than previously, removing the need
for the +1 in the caller.
---
 java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java 
b/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
index 063f462..7da9ea8 100644
--- a/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
+++ b/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
@@ -117,7 +117,7 @@ public class ChunkedOutputFilter implements OutputFilter {
 
 int pos = calculateChunkHeader(result);
 
-chunkHeader.position(pos + 1).limit(10);
+chunkHeader.position(pos).limit(10);
 buffer.doWrite(chunkHeader);
 
 buffer.doWrite(chunk);
@@ -132,12 +132,12 @@ public class ChunkedOutputFilter implements OutputFilter {
 
 private int calculateChunkHeader(int len) {
 // Calculate chunk header
-int pos = 7;
+int pos = 8;
 int current = len;
 while (current > 0) {
 int digit = current % 16;
 current = current / 16;
-chunkHeader.put(pos--, HexUtils.getHex(digit));
+chunkHeader.put(--pos, HexUtils.getHex(digit));
 }
 return pos;
 }


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



[tomcat] 02/02: Simplify

2019-09-09 Thread markt
This is an automated email from the ASF dual-hosted git repository.

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

commit 965792e2bf9126165f7a402c105e7fd669bd60f6
Author: Mark Thomas 
AuthorDate: Mon Sep 9 11:40:09 2019 +0100

Simplify

In calculateChunkHeader() start pos at 8 rather than 7 and then
decrement before it is used rather than after. This results in the same
number of decrement calls and the same values used in chunkHeader.put()
but the returned value is 1 higher than previously, removing the need
for the +1 in the caller.
---
 java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java 
b/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
index b382683..6eedd81 100644
--- a/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
+++ b/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
@@ -106,7 +106,7 @@ public class ChunkedOutputFilter implements OutputFilter {
 
 int pos = calculateChunkHeader(result);
 
-chunkHeader.position(pos + 1).limit(10);
+chunkHeader.position(pos).limit(10);
 buffer.doWrite(chunkHeader);
 
 buffer.doWrite(chunk);
@@ -120,12 +120,12 @@ public class ChunkedOutputFilter implements OutputFilter {
 
 private int calculateChunkHeader(int len) {
 // Calculate chunk header
-int pos = 7;
+int pos = 8;
 int current = len;
 while (current > 0) {
 int digit = current % 16;
 current = current / 16;
-chunkHeader.put(pos--, HexUtils.getHex(digit));
+chunkHeader.put(--pos, HexUtils.getHex(digit));
 }
 return pos;
 }


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



[tomcat] 02/02: Simplify

2019-06-28 Thread markt
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

commit ab21a87a897bb5aef02a7cb5e751139eb9d9b10b
Author: Mark Thomas 
AuthorDate: Fri Jun 28 22:23:21 2019 +0100

Simplify
---
 java/org/apache/catalina/connector/CoyoteAdapter.java | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java 
b/java/org/apache/catalina/connector/CoyoteAdapter.java
index 5727b60..e94a3d7 100644
--- a/java/org/apache/catalina/connector/CoyoteAdapter.java
+++ b/java/org/apache/catalina/connector/CoyoteAdapter.java
@@ -604,13 +604,11 @@ public class CoyoteAdapter implements Adapter {
 if (undecodedURI.equals("*")) {
 if (req.method().equalsIgnoreCase("OPTIONS")) {
 StringBuilder allow = new StringBuilder();
-allow.append("GET, HEAD, POST, PUT, DELETE");
+allow.append("GET, HEAD, POST, PUT, DELETE, OPTIONS");
 // Trace if allowed
 if (connector.getAllowTrace()) {
 allow.append(", TRACE");
 }
-// Always allow options
-allow.append(", OPTIONS");
 res.setHeader("Allow", allow.toString());
 // Access log entry as processing won't reach AccessLogValve
 connector.getService().getContainer().logAccess(request, 
response, 0, true);


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