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 5baec17 Refactor Hostname validation to improve performance. 5baec17 is described below commit 5baec176fae84302fde213db39d45d758151d63a Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue Apr 30 12:17:23 2019 +0100 Refactor Hostname validation to improve performance. Patch provided by Uwe Hees. --- java/org/apache/tomcat/util/http/parser/HttpParser.java | 16 ++++++++-------- .../tomcat/util/http/parser/TesterHostPerformance.java | 1 + webapps/docs/changelog.xml | 4 ++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/java/org/apache/tomcat/util/http/parser/HttpParser.java b/java/org/apache/tomcat/util/http/parser/HttpParser.java index 9523a50..8702059 100644 --- a/java/org/apache/tomcat/util/http/parser/HttpParser.java +++ b/java/org/apache/tomcat/util/http/parser/HttpParser.java @@ -890,7 +890,14 @@ public class HttpParser { } public DomainParseState next(int c) { - if (HttpParser.isAlpha(c)) { + if (c == -1) { + if (allowsEnd) { + return END; + } else { + throw new IllegalArgumentException( + sm.getString("http.invalidSegmentEndState", this.name())); + } + } else if (HttpParser.isAlpha(c)) { return ALPHA; } else if (HttpParser.isNumeric(c)) { return NUMERIC; @@ -908,13 +915,6 @@ public class HttpParser { throw new IllegalArgumentException(sm.getString(errorMsg, Character.toString((char) c))); } - } else if (c == -1) { - if (allowsEnd) { - return END; - } else { - throw new IllegalArgumentException( - sm.getString("http.invalidSegmentEndState", this.name())); - } } else if (c == '-') { if (allowsHyphen) { return HYPHEN; diff --git a/test/org/apache/tomcat/util/http/parser/TesterHostPerformance.java b/test/org/apache/tomcat/util/http/parser/TesterHostPerformance.java index a6c3e75..b579be3 100644 --- a/test/org/apache/tomcat/util/http/parser/TesterHostPerformance.java +++ b/test/org/apache/tomcat/util/http/parser/TesterHostPerformance.java @@ -36,6 +36,7 @@ public class TesterHostPerformance { List<Object[]> result = new ArrayList<>(); result.add(new Object[] { "localhost" }); result.add(new Object[] { "tomcat.apache.org" }); + result.add(new Object[] { "tomcat.apache.org." }); result.add(new Object[] { "127.0.0.1" }); result.add(new Object[] { "255.255.255.255" }); result.add(new Object[] { "[::1]" }); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 0cd436c..ee1c505 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -152,6 +152,10 @@ Update the HTTP/2 connection preface and initial frame reading to be asynchronous instead of blocking IO. (remm) </update> + <scode> + Refactor Hostname validation to improve performance. Patch provided by + Uwe Hees. (markt) + </scode> </changelog> </subsection> <subsection name="Other"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org