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 a05ab622216813d95ae38e21752f3b4dc54037cb 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 4fec1ca..f22f913 100644 --- a/java/org/apache/coyote/http11/Http11Processor.java +++ b/java/org/apache/coyote/http11/Http11Processor.java @@ -1030,20 +1030,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 @@ -1091,11 +1081,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; } } @@ -1121,11 +1107,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"); } } } @@ -1136,11 +1118,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"); } } @@ -1148,11 +1126,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; } } @@ -1214,6 +1188,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