Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java

Issue 29603560: Issue 6023 - Connection is not closed if response code was not 200 (Closed)
Patch Set: Created Nov. 10, 2017, 9:47 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java
diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java
index b6329cea7871472ac4d581d624d19e7a712a10af..595c459abda79fa0680459a12e38e3f4e42e1b24 100644
--- a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java
+++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java
@@ -128,73 +128,78 @@ public class AndroidWebRequest implements WebRequest
connection.connect();
final ServerResponse response = new ServerResponse();
- response.setResponseStatus(connection.getResponseCode());
-
- if (response.getResponseStatus() == 200)
+ try
{
- final InputStream inputStream =
- (compressedStream && ENCODING_GZIP.equals(connection.getContentEncoding())
- ? new GZIPInputStream(connection.getInputStream())
- : connection.getInputStream());
- final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
- final StringBuilder sb = new StringBuilder();
-
- String line;
- try
+ response.setResponseStatus(connection.getResponseCode());
+
+ if (response.getResponseStatus() == 200)
{
- while ((line = reader.readLine()) != null)
+ final InputStream inputStream =
+ (compressedStream && ENCODING_GZIP.equals(connection.getContentEncoding())
+ ? new GZIPInputStream(connection.getInputStream())
+ : connection.getInputStream());
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
+ final StringBuilder sb = new StringBuilder();
+
+ String line;
+ try
{
- // We're only appending non-element-hiding filters here.
- //
- // See:
- // https://issues.adblockplus.org/ticket/303
- //
- // Follow-up issue for removing this hack:
- // https://issues.adblockplus.org/ticket/1541
- //
- if (this.elemhideEnabled || !isListedSubscriptionUrl(url) || line.indexOf('#') == -1)
+ while ((line = reader.readLine()) != null)
{
- sb.append(line);
- sb.append('\n');
+ // We're only appending non-element-hiding filters here.
+ //
+ // See:
+ // https://issues.adblockplus.org/ticket/303
+ //
+ // Follow-up issue for removing this hack:
+ // https://issues.adblockplus.org/ticket/1541
+ //
+ if (this.elemhideEnabled || !isListedSubscriptionUrl(url) || line.indexOf('#') == -1)
+ {
+ sb.append(line);
+ sb.append('\n');
+ }
}
}
- }
- finally
- {
- try
- {
- reader.close();
- }
- catch (IOException e)
+ finally
{
- // ignored
+ try
+ {
+ reader.close();
+ }
+ catch (IOException e)
+ {
+ // ignored
+ }
}
- }
- response.setStatus(NsStatus.OK);
- response.setResponse(sb.toString());
+ response.setStatus(NsStatus.OK);
+ response.setResponse(sb.toString());
- if (connection.getHeaderFields().size() > 0)
- {
- List<HeaderEntry> responseHeaders = new LinkedList<HeaderEntry>();
- for (Map.Entry<String, List<String>> eachEntry : connection.getHeaderFields().entrySet())
+ if (connection.getHeaderFields().size() > 0)
{
- for (String eachValue : eachEntry.getValue())
+ List<HeaderEntry> responseHeaders = new LinkedList<HeaderEntry>();
+ for (Map.Entry<String, List<String>> eachEntry : connection.getHeaderFields().entrySet())
{
- if (eachEntry.getKey() != null && eachValue != null)
+ for (String eachValue : eachEntry.getValue())
{
- responseHeaders.add(new HeaderEntry(eachEntry.getKey().toLowerCase(), eachValue));
+ if (eachEntry.getKey() != null && eachValue != null)
+ {
+ responseHeaders.add(new HeaderEntry(eachEntry.getKey().toLowerCase(), eachValue));
+ }
}
}
+ response.setReponseHeaders(responseHeaders);
}
- response.setReponseHeaders(responseHeaders);
}
-
- connection.disconnect();
+ else
+ {
+ response.setStatus(NsStatus.ERROR_FAILURE);
+ }
}
- else
+ finally
{
- response.setStatus(NsStatus.ERROR_FAILURE);
+ connection.disconnect();
}
Log.d(TAG, "Downloading finished");
return response;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld