if (DEBUG) _log.debug(
"Performing HTTP " + (useGet ? "GET" : "HEAD") +
" on: " + url + " ...");
HttpRequestOptions requestOptions = _httpFetcher.getRequestOptions();
requestOptions.setMaxRedirects(maxRedirects);
if (useGet)
{
if (attempt == 1)
requestOptions.addRequestHeader("Accept", YADIS_ACCEPT_HEADER);
else
requestOptions.addRequestHeader("Accept", YADIS_CONTENT_TYPE);
}
HttpResponse resp = useGet ?
_httpFetcher.get(url.getUrl().toString(), requestOptions) :
_httpFetcher.head(url.getUrl().toString(), requestOptions);
Header[] locationHeaders = resp.getResponseHeaders(YADIS_XRDS_LOCATION);
Header contentType = resp.getResponseHeader("content-type");
if (HttpStatus.SC_OK != resp.getStatusCode())
{
// won't be able to recover from a GET error, throw
if (useGet)
throw new YadisException("GET failed on " + url + " : " +
resp.getStatusCode(), OpenIDException.YADIS_GET_ERROR);
// HEAD is optional, will fall-back to GET
if (DEBUG)
_log.debug("Cannot retrieve " + YADIS_XRDS_LOCATION +
" using HEAD from " + url.getUrl().toString() +
"; status=" + resp.getStatusCode());
}
else if ((locationHeaders != null && locationHeaders.length > 1))
{
// fail if there are more than one YADIS_XRDS_LOCATION headers
throw new YadisException("Found " + locationHeaders.length +
" " + YADIS_XRDS_LOCATION + " headers.",
useGet ? OpenIDException.YADIS_GET_INVALID_RESPONSE :
OpenIDException.YADIS_HEAD_INVALID_RESPONSE);
}
else if (locationHeaders != null && locationHeaders.length > 0)
{
// we have exactly one xrds location header
result.setXrdsLocation(locationHeaders[0].getValue(),
useGet ? OpenIDException.YADIS_GET_INVALID_RESPONSE :
OpenIDException.YADIS_HEAD_INVALID_RESPONSE);
result.setNormalizedUrl(resp.getFinalUri());
}
else if (contentType != null && contentType.getValue() != null &&
contentType.getValue().split(";")[0].equalsIgnoreCase(YADIS_CONTENT_TYPE) &&
resp.getBody() != null)
{
// no location, but got xrds document
result.setNormalizedUrl(resp.getFinalUri());
result.setContentType(contentType.getValue());
if (resp.isBodySizeExceeded())
throw new YadisException(
"More than " + requestOptions.getMaxBodySize() +
" bytes in HTTP response body from " + url,
OpenIDException.YADIS_XRDS_SIZE_EXCEEDED);
result.setEndpoints(XRDS_PARSER.parseXrds(resp.getBody(), serviceTypes));
}
else if (resp.getBody() != null)