Commits

Sebastian Sdorra  committed 45037cb

added support for forwarding, see #25

  • Participants
  • Parent commits 8ca7e76

Comments (0)

Files changed (1)

File third-party/svnkit-dav/src/main/java/org/tmatesoft/svn/core/internal/server/dav/DAVServletUtil.java

  * @author  TMate Software Ltd.
  */
 public class DAVServletUtil {
+  
+    public static final String HEADER_FORWARDHOST = "X-Forwarded-Host";
     
     public static long getSafeCreatedRevision(FSRevisionRoot root, String path) {
         long revision = root.getRevision();
             throw new DAVException("Destination URI contains invalid components (a query or a fragment).", HttpServletResponse.SC_BAD_REQUEST, 0);
         }
         
-        if (parsedURI.getScheme() != null || parsedURI.getPort() != -1 || mustBeAbsolute) {
-            String scheme = request.getScheme();
-            if (scheme == null) {
-                //TODO: replace this code in future 
-                scheme = "http";
-            }
-            int parsedPort = parsedURI.getPort();
-            if (parsedURI.getPort() == -1) {
-                parsedPort = request.getServerPort();
-            }
-            
-            if (!scheme.equals(parsedURI.getScheme()) || parsedPort != request.getServerPort()) {
-                throw new DAVException("Destination URI refers to different scheme or port ({0}://hostname:{1})\n(want: {2}://hostname:{3})", 
-                        new Object[] { parsedURI.getScheme() != null ? parsedURI.getScheme() : scheme, String.valueOf(parsedPort), scheme, 
-                                String.valueOf(request.getServerPort()) }, HttpServletResponse.SC_BAD_REQUEST, 0);
-            }
+        String serverHost = request.getServerName();
+        String forwardedHost = request.getHeader(HEADER_FORWARDHOST);
+        
+        // skip scheme and port check if the request is forwarded, see scmmanager #25
+        if ( forwardedHost == null || forwardedHost.length() == 0 ){
+        
+          if (parsedURI.getScheme() != null || parsedURI.getPort() != -1 || mustBeAbsolute) {
+              String scheme = request.getScheme();
+              if (scheme == null) {
+                  //TODO: replace this code in future 
+                  scheme = "http";
+              }
+              int parsedPort = parsedURI.getPort();
+              if (parsedURI.getPort() == -1) {
+                  parsedPort = request.getServerPort();
+              }
+
+              if (!scheme.equals(parsedURI.getScheme()) || parsedPort != request.getServerPort()) {
+                  throw new DAVException("Destination URI refers to different scheme or port ({0}://hostname:{1})\n(want: {2}://hostname:{3})", 
+                          new Object[] { parsedURI.getScheme() != null ? parsedURI.getScheme() : scheme, String.valueOf(parsedPort), scheme, 
+                                  String.valueOf(request.getServerPort()) }, HttpServletResponse.SC_BAD_REQUEST, 0);
+              }
+          }
+        
+        } else {
+          // use forward host for host check
+          serverHost = forwardedHost;
         }
         
         String parsedHost = parsedURI.getHost();
-        String serverHost = request.getServerName();
+        
         String domain = null;
         int domainInd = serverHost != null ? serverHost.indexOf('.') : -1;  
         if (domainInd != -1) {
             parsedHost += domain;
         }
         
-        if (parsedHost != null && !parsedHost.equals(request.getServerName())) {
+        if (parsedHost != null && !parsedHost.equals(serverHost)) {
             throw new DAVException("Destination URI refers to a different server.", HttpServletResponse.SC_BAD_GATEWAY, 0);
         }
         return parsedURI;