private void handleRedirects(final HttpClient client, final HttpMethod method, final int curRedirAm, final int maxRedirAm) throws HttpException,
            IOException {
        if (logger.isEnabled(Level.DEBUG)) {
            logger.log(Level.DEBUG, "Executing " + method + " redir count = " + curRedirAm + " of " + maxRedirAm + " possible redirects ");
        }
        // exec and see what happened
        client.executeMethod(method);
        int code = method.getStatusCode();
        if (logger.isEnabled(Level.DEBUG)) {
            logger.log(Level.DEBUG, "Executing " + method + " got status code " + code + "");
        }
        // supposed redirect codes
        // everything else will just stop this function
        if (REDIR_CODES.contains(code) == false) {
            return;
        }
        // die or continue?
        if (curRedirAm < maxRedirAm) {
            // ok to try to find it
            Header locationHeader = method.getResponseHeader(REDIR_HEADER);
            String redirLoc = null;
            if (locationHeader != null) {
                redirLoc = locationHeader.getValue();
            }
            // cleanup and see if we can use it...
            redirLoc = StringUtils.trim(redirLoc);
            if (StringUtils.isEmpty(redirLoc) == false) {
                // reset uri
                URI nUri = new URI(redirLoc, false);
                method.setURI(nUri);
                if (logger.isEnabled(Level.DEBUG)) {
                    logger.log(Level.DEBUG, "Attempting redirect " + (curRedirAm + 1) + " due to status code " + code + " to location " + nUri);
                }
                handleRedirects(client, method, curRedirAm + 1, maxRedirAm);
            }
            else {
                // failure at finding header
                throw new HttpException("Unable to execute " + method + " - no " + REDIR_HEADER + " header found to redirect to during redirect "
                        + curRedirAm);
            }
        }
        else {
            // max redirects done
            throw new HttpException("Unable to execute " + method + " after attempting " + curRedirAm + " redirects of " + maxRedirAm + " attempts");
        }
    }