markt-asf commented on code in PR #818:
URL: https://github.com/apache/tomcat/pull/818#discussion_r1939680064


##########
java/org/apache/tomcat/util/http/RequestUtil.java:
##########
@@ -123,19 +123,12 @@ public static boolean isSameOrigin(HttpServletRequest 
request, String origin) {
         // Build scheme://host:port from request
         StringBuilder target = new StringBuilder();
         String scheme = request.getScheme();
-        if (scheme == null) {
-            return false;
-        } else {
-            scheme = scheme.toLowerCase(Locale.ENGLISH);
-        }
-        target.append(scheme);
-        target.append("://");
-
         String host = request.getServerName();
-        if (host == null) {
+        if (scheme == null || host == null) {
             return false;
         }
-        target.append(host);
+        scheme = scheme.toLowerCase(Locale.ENGLISH);
+        target.append(scheme).append("://").append(host);

Review Comment:
   This is ever so slightly less efficient if scheme is null but I do like that 
the code is a lot more compact. I don't think it is worth checking scheme for 
null before retrieving the host so +1 to the change as proposed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to