Make sure URL connection is closed

pull/200/head
M66B 4 years ago
parent 64e48fdc76
commit b8e04341ab

@ -354,7 +354,7 @@ public class ContactInfo {
emailGravatar.put(gkey, new Gravatar(false)); emailGravatar.put(gkey, new Gravatar(false));
} }
} else } else
throw new IOException("HTTP status=" + status); throw new IOException("Error " + status + ": " + urlConnection.getResponseMessage());
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
@ -907,7 +907,7 @@ public class ContactInfo {
try { try {
int status = connection.getResponseCode(); int status = connection.getResponseCode();
if (status != HttpURLConnection.HTTP_OK) if (status != HttpURLConnection.HTTP_OK)
throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage()); throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage());
if ("image/svg+xml".equals(type) || url.getPath().endsWith(".svg")) { if ("image/svg+xml".equals(type) || url.getPath().endsWith(".svg")) {
Bitmap bitmap = ImageHelper.renderSvg(connection.getInputStream(), Color.WHITE, scaleToPixels); Bitmap bitmap = ImageHelper.renderSvg(connection.getInputStream(), Color.WHITE, scaleToPixels);

@ -123,7 +123,7 @@ public class DisconnectBlacklist {
try { try {
int status = connection.getResponseCode(); int status = connection.getResponseCode();
if (status != HttpsURLConnection.HTTP_OK) if (status != HttpsURLConnection.HTTP_OK)
throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage()); throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage());
String response = Helper.readStream(connection.getInputStream()); String response = Helper.readStream(connection.getInputStream());
Helper.writeText(file, response); Helper.writeText(file, response);

@ -391,7 +391,7 @@ public class EmailProvider implements Parcelable {
int status = request.getResponseCode(); int status = request.getResponseCode();
if (status != HttpURLConnection.HTTP_OK) if (status != HttpURLConnection.HTTP_OK)
throw new FileNotFoundException("Error " + status + ":" + request.getResponseMessage()); throw new FileNotFoundException("Error " + status + ": " + request.getResponseMessage());
// https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser // https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

@ -8037,7 +8037,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
try { try {
int status = connection.getResponseCode(); int status = connection.getResponseCode();
if (status != HttpURLConnection.HTTP_OK) if (status != HttpURLConnection.HTTP_OK)
throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage()); throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage());
Helper.copy(connection.getInputStream(), os); Helper.copy(connection.getInputStream(), os);
} finally { } finally {

@ -598,7 +598,7 @@ public class FragmentOAuth extends FragmentBase {
try { try {
int status = connection.getResponseCode(); int status = connection.getResponseCode();
if (status != HttpsURLConnection.HTTP_OK) if (status != HttpsURLConnection.HTTP_OK)
throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage()); throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage());
String json = Helper.readStream(connection.getInputStream()); String json = Helper.readStream(connection.getInputStream());
Log.i("json=" + json); Log.i("json=" + json);

@ -82,7 +82,7 @@ public class IPInfo {
try { try {
int status = connection.getResponseCode(); int status = connection.getResponseCode();
if (status != HttpsURLConnection.HTTP_OK) if (status != HttpsURLConnection.HTTP_OK)
throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage()); throw new FileNotFoundException("Error " + status + ": " + connection.getResponseMessage());
String response = Helper.readStream(connection.getInputStream()); String response = Helper.readStream(connection.getInputStream());
organization.name = response.trim(); organization.name = response.trim();

@ -639,31 +639,36 @@ class ImageHelper {
urlConnection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context)); urlConnection.setRequestProperty("User-Agent", WebViewEx.getUserAgent(context));
urlConnection.connect(); urlConnection.connect();
int status = urlConnection.getResponseCode(); try {
int status = urlConnection.getResponseCode();
if (status == HttpURLConnection.HTTP_MOVED_PERM ||
status == HttpURLConnection.HTTP_MOVED_TEMP || if (status == HttpURLConnection.HTTP_MOVED_PERM ||
status == HttpURLConnection.HTTP_SEE_OTHER || status == HttpURLConnection.HTTP_MOVED_TEMP ||
status == 307 /* Temporary redirect */ || status == HttpURLConnection.HTTP_SEE_OTHER ||
status == 308 /* Permanent redirect */) { status == 307 /* Temporary redirect */ ||
if (++redirects > MAX_REDIRECTS) status == 308 /* Permanent redirect */) {
throw new IOException("Too many redirects"); if (++redirects > MAX_REDIRECTS)
throw new IOException("Too many redirects");
String header = urlConnection.getHeaderField("Location");
if (header == null) String header = urlConnection.getHeaderField("Location");
throw new IOException("Location header missing"); if (header == null)
throw new IOException("Location header missing");
String location = URLDecoder.decode(header, StandardCharsets.UTF_8.name());
url = new URL(url, location); String location = URLDecoder.decode(header, StandardCharsets.UTF_8.name());
Log.i("Redirect #" + redirects + " to " + url); url = new URL(url, location);
Log.i("Redirect #" + redirects + " to " + url);
urlConnection.disconnect();
continue;
}
if (status != HttpURLConnection.HTTP_OK)
throw new IOException("Error " + status + ": " + urlConnection.getResponseMessage());
} catch (IOException ex) {
urlConnection.disconnect(); urlConnection.disconnect();
continue; throw ex;
} }
if (status != HttpURLConnection.HTTP_OK)
throw new IOException("HTTP status=" + status);
break; break;
} }

Loading…
Cancel
Save