Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51972
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 10 Oct 2011 12:10:53 +0000 (12:10 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 10 Oct 2011 12:10:53 +0000 (12:10 +0000)
Add support for handling scheme/protocol relative URLs for redirects

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1180907 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/connector/Response.java

index d434f66..014d8e1 100644 (file)
@@ -1591,7 +1591,24 @@ public class Response
 
         boolean leadingSlash = location.startsWith("/");
 
-        if (leadingSlash || !hasScheme(location)) {
+        if (location.startsWith("//")) {
+            // Scheme relative
+            redirectURLCC.recycle();
+            // Add the scheme
+            String scheme = request.getScheme();
+                try {
+                redirectURLCC.append(scheme, 0, scheme.length());
+                redirectURLCC.append(':');
+                redirectURLCC.append(location, 0, location.length());
+                return redirectURLCC.toString();
+            } catch (IOException e) {
+                IllegalArgumentException iae =
+                    new IllegalArgumentException(location);
+                iae.initCause(e);
+                throw iae;
+            }
+
+        } else if (leadingSlash || !hasScheme(location)) {
 
             redirectURLCC.recycle();