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 aaa63d2f25b3d3f367d91674d25c32de037d3e39 Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Jul 24 11:35:52 2019 +0100 Refactor to reduce duplication --- .../coyote/http11/AbstractHttp11Processor.java | 48 +++++++--------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/java/org/apache/coyote/http11/AbstractHttp11Processor.java b/java/org/apache/coyote/http11/AbstractHttp11Processor.java index 615172e..ae0bb2f 100644 --- a/java/org/apache/coyote/http11/AbstractHttp11Processor.java +++ b/java/org/apache/coyote/http11/AbstractHttp11Processor.java @@ -1358,20 +1358,10 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> { hostValueMB = headers.getUniqueValue("host"); } catch (IllegalArgumentException iae) { // Multiple Host headers are not permitted - // 400 - Bad request - response.setStatus(400); - setErrorState(ErrorState.CLOSE_CLEAN, null); - if (getLog().isDebugEnabled()) { - getLog().debug(sm.getString("http11processor.request.multipleHosts")); - } + badRequest("http11processor.request.multipleHosts"); } if (http11 && hostValueMB == null) { - // 400 - Bad request - response.setStatus(400); - setErrorState(ErrorState.CLOSE_CLEAN, null); - if (getLog().isDebugEnabled()) { - getLog().debug(sm.getString("http11processor.request.noHostHeader")); - } + badRequest("http11processor.request.noHostHeader"); } // Check for an absolute-URI less the query string which has already @@ -1419,11 +1409,7 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> { // Strictly there needs to be a check for valid %nn // encoding here but skip it since it will never be // decoded because the userinfo is ignored - response.setStatus(400); - setErrorState(ErrorState.CLOSE_CLEAN, null); - if (getLog().isDebugEnabled()) { - getLog().debug(sm.getString("http11processor.request.invalidUserInfo")); - } + badRequest("http11processor.request.invalidUserInfo"); break; } } @@ -1449,11 +1435,7 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> { // The requirements of RFC 7230 are being // applied. If the host header and the request // line do not agree, trigger a 400 response. - response.setStatus(400); - setErrorState(ErrorState.CLOSE_CLEAN, null); - if (getLog().isDebugEnabled()) { - getLog().debug(sm.getString("http11processor.request.inconsistentHosts")); - } + badRequest("http11processor.request.inconsistentHosts"); } } } @@ -1464,24 +1446,15 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> { hostValueMB.setBytes(uriB, uriBCStart + pos, slashPos - pos); } } else { - response.setStatus(400); - setErrorState(ErrorState.CLOSE_CLEAN, null); - if (getLog().isDebugEnabled()) { - getLog().debug(sm.getString("http11processor.request.invalidScheme")); - } + badRequest("http11processor.request.invalidScheme"); } - } // Validate the characters in the URI. %nn decoding will be checked at // the point of decoding. for (int i = uriBC.getStart(); i < uriBC.getEnd(); i++) { if (!httpParser.isAbsolutePathRelaxed(uriB[i])) { - response.setStatus(400); - setErrorState(ErrorState.CLOSE_CLEAN, null); - if (getLog().isDebugEnabled()) { - getLog().debug(sm.getString("http11processor.request.invalidUri")); - } + badRequest("http11processor.request.invalidUri"); break; } } @@ -1563,6 +1536,15 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> { } + private void badRequest(String errorKey) { + response.setStatus(400); + setErrorState(ErrorState.CLOSE_CLEAN, null); + if (getLog().isDebugEnabled()) { + getLog().debug(sm.getString(errorKey)); + } + } + + /** * Connector implementation specific request preparation. Ideally, this will * go away in the future. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org