protected String toAbsolute(String location) {
            String url = location;
            boolean leadingSlash = url.startsWith("/");
            StringBuilder urlBuilder = new StringBuilder();
            if (leadingSlash || !hasScheme(url)) {
                String scheme = xRequest.getScheme();
                String name = xRequest.getServerName();
                int port = xRequest.getServerPort();
                urlBuilder.append(scheme);
                urlBuilder.append("://");
                urlBuilder.append(name);
                if ((scheme.equals("http") && port != 80)
                    || (scheme.equals("https") && port != 443)) {
                    urlBuilder.append(':');
                    urlBuilder.append(port);
                }
                if (!leadingSlash) {
                    String requestURI = xRequest.getRequestURI();
                    int pos = requestURI.lastIndexOf("/");
                    requestURI = requestURI.substring(0, pos);
                    urlBuilder.append(requestURI);
                    urlBuilder.append("/");
                }
                urlBuilder.append(url);
                url = urlBuilder.toString();
            }
            return url;
        }