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
The following commit(s) were added to refs/heads/master by this push: new 667d0e8 Refactor to reduce duplication 667d0e8 is described below commit 667d0e83c5415ff8e99ee088c41601edd7c8ca07 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue Jul 23 13:55:31 2019 +0100 Refactor to reduce duplication --- java/org/apache/coyote/http11/Http11Processor.java | 47 +++++++--------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java index e272a92..6542619 100644 --- a/java/org/apache/coyote/http11/Http11Processor.java +++ b/java/org/apache/coyote/http11/Http11Processor.java @@ -639,20 +639,10 @@ public class Http11Processor extends AbstractProcessor { 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 (log.isDebugEnabled()) { - log.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 (log.isDebugEnabled()) { - log.debug(sm.getString("http11processor.request.noHostHeader")); - } + badRequest("http11processor.request.noHostHeader"); } // Check for an absolute-URI less the query string which has already @@ -700,11 +690,7 @@ public class Http11Processor extends AbstractProcessor { // 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 (log.isDebugEnabled()) { - log.debug(sm.getString("http11processor.request.invalidUserInfo")); - } + badRequest("http11processor.request.invalidUserInfo"); break; } } @@ -730,11 +716,7 @@ public class Http11Processor extends AbstractProcessor { // 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 (log.isDebugEnabled()) { - log.debug(sm.getString("http11processor.request.inconsistentHosts")); - } + badRequest("http11processor.request.inconsistentHosts"); } } } @@ -745,11 +727,7 @@ public class Http11Processor extends AbstractProcessor { hostValueMB.setBytes(uriB, uriBCStart + pos, slashPos - pos); } } else { - response.setStatus(400); - setErrorState(ErrorState.CLOSE_CLEAN, null); - if (log.isDebugEnabled()) { - log.debug(sm.getString("http11processor.request.invalidScheme")); - } + badRequest("http11processor.request.invalidScheme"); } } @@ -757,11 +735,7 @@ public class Http11Processor extends AbstractProcessor { // 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 (log.isDebugEnabled()) { - log.debug(sm.getString("http11processor.request.invalidUri")); - } + badRequest("http11processor.request.invalidUri"); break; } } @@ -823,6 +797,15 @@ public class Http11Processor extends AbstractProcessor { } + private void badRequest(String errorKey) { + response.setStatus(400); + setErrorState(ErrorState.CLOSE_CLEAN, null); + if (log.isDebugEnabled()) { + log.debug(sm.getString(errorKey)); + } + } + + /** * When committing the response, we have to validate the set of headers, as * well as setup the response filters. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org