* @return
*/
public Page download(URL url) throws DownloadException {
Request request = createRequest(url);
Page page = null;
for (int i = 0; i < triesCount; i++) {
try {
log.debug("Downloading from " + url + ", try number " + (i + 1));
// Using proxy
Proxy proxy = proxyController == null ? null : proxyController.getProxy();
// If head request is needed - executing and checking constraints
if (headRequest) {
// Sending HEAD request using specified proxy
Page headPage = headRequest(request, proxy);
// This is a redirect
if (headPage != null && headPage.getResponseCode() >= 300 && headPage.getResponseCode() < 400) {
log.debug("Server redirected our request to " + url);
// No need to request it again
return headPage;
}
// Error response code
if (headPage.getResponseCode() >= 400) {
log.debug("Cannot download " + request.getUrl() + (proxy == null ? "" : " through proxy " + proxy) + ", response code is " + headPage.getResponseCode());
if (i == (triesCount - 1)) {
return headPage;
} else {
waitForRetry(request);
continue;