private String parseDestinationHeader ( final WebdavRequest req , final WebdavResponse resp ) throws IOException { String destinationPath = req . getHeader ( "Destination" ) ; if ( destinationPath == null ) { resp . sendError ( WebdavStatus . SC_BAD_REQUEST ) ; return null ; } // Remove url encoding from destination destinationPath = RequestUtil . URLDecode ( destinationPath , "UTF8" ) ; final int protocolIndex = destinationPath . indexOf ( "://" ) ; if ( protocolIndex >= 0 ) { // if the Destination URL contains the protocol, we can safely // trim everything upto the first "/" character after "://" final int firstSeparator = destinationPath . indexOf ( "/" , protocolIndex + 4 ) ; if ( firstSeparator < 0 ) { destinationPath = "/" ; } else { destinationPath = destinationPath . substring ( firstSeparator ) ; } } else { final String hostName = req . getServerName ( ) ; if ( ( hostName != null ) && ( destinationPath . startsWith ( hostName ) ) ) { destinationPath = destinationPath . substring ( hostName . length ( ) ) ; } final int portIndex = destinationPath . indexOf ( ":" ) ; if ( portIndex >= 0 ) { destinationPath = destinationPath . substring ( portIndex ) ; } if ( destinationPath . startsWith ( ":" ) ) { final int firstSeparator = destinationPath . indexOf ( "/" ) ; if ( firstSeparator < 0 ) { destinationPath = "/" ; } else { destinationPath = destinationPath . substring ( firstSeparator ) ; } } } // Normalize destination path (remove '.' and' ..') destinationPath = normalize ( destinationPath ) ; final String contextPath = req . getContextPath ( ) ; if ( ( contextPath != null ) && ( destinationPath . startsWith ( contextPath ) ) ) { destinationPath = destinationPath . substring ( contextPath . length ( ) ) ; } final String pathInfo = req . getPathInfo ( ) ; if ( pathInfo != null ) { final String servletPath = req . getServicePath ( ) ; if ( ( servletPath != null ) && ( destinationPath . startsWith ( servletPath ) ) ) { destinationPath = destinationPath . substring ( servletPath . length ( ) ) ; } } return destinationPath ; }
Parses and normalizes the destination header .