code: private String parseDestinationHeader(HttpServletRequest req) {
  
          // Parsing destination header
          String destinationPath = req.getHeader(HEADER_DESTINATION);
  
          if (destinationPath == null) {
              return null;
          }
  
          // Remove url encoding from destination
          destinationPath = CmsEncoder.decode(destinationPath, "UTF8");
  
          int protocolIndex = destinationPath.indexOf("://");
          if (protocolIndex >= 0) {
  
              // if the Destination URL contains the protocol, we can safely
              // trim everything upto the first "/" character after "://"
              int firstSeparator = destinationPath.indexOf("/", protocolIndex + 4);
              if (firstSeparator < 0) {
                  destinationPath = "/";
              } else {
                  destinationPath = destinationPath.substring(firstSeparator);
              }
          } else {
              String hostName = req.getServerName();
              if ((hostName != null) && (destinationPath.startsWith(hostName))) {
                  destinationPath = destinationPath.substring(hostName.length());
              }
  
              int portIndex = destinationPath.indexOf(":");
              if (portIndex >= 0) {
                  destinationPath = destinationPath.substring(portIndex);
              }
  
              if (destinationPath.startsWith(":")) {
                  int firstSeparator = destinationPath.indexOf("/");
                  if (firstSeparator < 0) {
                      destinationPath = "/";
                  } else {
                      destinationPath = destinationPath.substring(firstSeparator);
                  }
              }
          }
  
          // Normalise destination path (remove '.' and '..')
          destinationPath = normalize(destinationPath);
  
          String contextPath = req.getContextPath();
          if ((contextPath != null) && (destinationPath.startsWith(contextPath))) {
              destinationPath = destinationPath.substring(contextPath.length());
          }
  
          String pathInfo = req.getPathInfo();
          if (pathInfo != null) {
              String servletPath = req.getServletPath();
              if ((servletPath != null) && (destinationPath.startsWith(servletPath))) {
                  destinationPath = destinationPath.substring(servletPath.length());
              }
          }
  
          return destinationPath;
      }
docs: Reads the information about a destination path out of the header of the
  request.<p>
  
  @param req the servlet request we are processing
  
  @return the destination path