import com.stoutner.privacybrowser.R;
import com.stoutner.privacybrowser.helpers.ProxyHelper;
-import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.Proxy;
Proxy proxy = proxyHelper.getCurrentProxy(context);
// Open a connection to the URL. No data is actually sent at this point.
- HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
+ HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection(proxy);
// Add the user agent to the header property.
- httpURLConnection.setRequestProperty("User-Agent", userAgent);
+ httpUrlConnection.setRequestProperty("User-Agent", userAgent);
// Add the cookies if they are enabled.
if (cookiesEnabled) {
// Only add the cookies if they are not null.
if (cookiesString != null) {
// Add the cookies to the header property.
- httpURLConnection.setRequestProperty("Cookie", cookiesString);
+ httpUrlConnection.setRequestProperty("Cookie", cookiesString);
}
}
// Exit if the task has been cancelled.
if (isCancelled()) {
// Disconnect the HTTP URL connection.
- httpURLConnection.disconnect();
+ httpUrlConnection.disconnect();
// Return the formatted file size string.
return formattedFileSize;
}
// Get the status code.
- int responseCode = httpURLConnection.getResponseCode();
+ int responseCode = httpUrlConnection.getResponseCode();
// Exit if the task has been cancelled.
if (isCancelled()) {
// Disconnect the HTTP URL connection.
- httpURLConnection.disconnect();
+ httpUrlConnection.disconnect();
// Return the formatted file size string.
return formattedFileSize;
// Check the response code.
if (responseCode >= 400) { // The response code is an error message.
// Set the formatted file size to indicate a bad URL.
- formattedFileSize = context.getString(R.string.bad_url);
+ formattedFileSize = context.getString(R.string.invalid_url);
} else { // The response code is not an error message.
// Get the content length header.
- String contentLengthString = httpURLConnection.getHeaderField("Content-Length");
+ String contentLengthString = httpUrlConnection.getHeaderField("Content-Length");
// Define the file size long.
long fileSize;
}
} finally {
// Disconnect the HTTP URL connection.
- httpURLConnection.disconnect();
+ httpUrlConnection.disconnect();
}
- } catch (IOException exception) {
+ } catch (Exception exception) {
// Set the formatted file size to indicate a bad URL.
- formattedFileSize = context.getString(R.string.bad_url);
+ formattedFileSize = context.getString(R.string.invalid_url);
}
// Return the formatted file size string.