@SuppressWarnings("checkstyle:MagicNumber")
    private String toAbsolute(String location) {

        if (location == null) {
            return (location);
        }

        boolean leadingSlash = location.startsWith("/");

        if (leadingSlash || !hasScheme(location)) {

            StringBuilder buf = new StringBuilder();

            String scheme = request.getScheme();
            String name = request.getServerName();
            int port = request.getServerPort();

            try {
                buf.append(scheme).append("://").append(name);
                if ((scheme.equals("http") && port != 80)
                        || (scheme.equals("https") && port != 443)) {
                    buf.append(':').append(port);
                }
                if (!leadingSlash) {
                    String relativePath = request.getRequestURI();
                    int pos = relativePath.lastIndexOf('/');
                    relativePath = relativePath.substring(0, pos);

                    String encodedURI = URLEncoder.encode(relativePath, getCharacterEncoding());
                    buf.append(encodedURI).append('/');
                }
                buf.append(location);
            } catch (IOException e) {
                IllegalArgumentException iae = new IllegalArgumentException(location);
                iae.initCause(e);
                throw iae;
            }

            return buf.toString();

        } else {
            return location;
        }
    }
Convert (if necessary) and return the absolute URL that represents the
resource referenced by this possibly relative URL.  If this URL is
already absolute, return it unchanged.

@param location URL to be (possibly) converted and then returned
@return resource location as an absolute url
@throws IllegalArgumentException if a MalformedURLException is
                                 thrown when converting the relative URL to an absolute one
web/src/main/java/org/apache/shiro/web/servlet/ShiroHttpServletResponse.java