Log.warn(SimpleUrlRetrieverModule.class, ".run: not tried because time left is too short. URL", url);
callback.onFailure(new IOException(
"BasicUrlRetrieverModule.loadUrl: timeout is less than 200ms. Not worth trying..."));
return;
}
HTTPRequest httpRequest = null;
String urlString = url.toString();
if (urlString.length() > Constants.MAX_URL_LENGTH) {
if (urlString.indexOf('?') < 0) {
Log.severe(
this,
"loadUrl: URL is longer than 2000 characters but there are no parameters that could be sent via POST (there is no \"?\" in the URL)! Thus, this URL can not be loaded. URL",
urlString);
// callback.onSuccess(new byte[0]);
// There is no data that can be loaded in a retry using this URL, thus success aka we did all we could.
callback.onSuccess(null);
}
Log.warn(this, "loadUrl: URL longer than 2000 characters. Trying POST mode...");
String[] urlSplit = urlString.split("\\?");
assert urlSplit.length == 2 : urlSplit;
try {
httpRequest = new HTTPRequest(new URL(urlSplit[0]), HTTPMethod.POST);
httpRequest.setPayload(urlSplit[1].getBytes(Constants.UTF8));
} catch (Throwable t) {
Log.warn(this, "loadUrl: URL longer than 2000 characters. Failed to convert to POST request! error", t);
}
}
if (httpRequest == null) {
httpRequest = new HTTPRequest(url);
}
httpRequest.getFetchOptions().disallowTruncate().doNotValidateCertificate().followRedirects();
if (timeout > 0) {
httpRequest.getFetchOptions().setDeadline(timeout / 1000d);
}
if (Util.notEmpty(requiredContentType)) {
httpRequest.setHeader(new HTTPHeader("Accept", requiredContentType));
}
urlRetriever.addRequest(httpRequest, callback);
}