mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-27 13:21:30 +00:00
We should close URLConnections
This commit is contained in:
parent
66a7cf45db
commit
4b0ec8b092
1 changed files with 7 additions and 2 deletions
|
@ -83,14 +83,19 @@ public abstract class RestTask<Params, Progress> extends
|
|||
*/
|
||||
protected Pair<Boolean, String> connect(HttpsURLConnection connection) throws IOException {
|
||||
connection.connect();
|
||||
Pair<Boolean, String> result;
|
||||
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
||||
int responseCode = connection.getResponseCode();
|
||||
String responseMessage = connection.getResponseMessage();
|
||||
Log.i(TAG, "Request to " + connection.getURL() + " failed, code: " + responseCode +
|
||||
", message: " + responseMessage);
|
||||
return new Pair<>(false, streamToString(connection.getErrorStream()));
|
||||
result = new Pair<>(false, streamToString(connection.getErrorStream()));
|
||||
}
|
||||
return new Pair<>(true, streamToString(connection.getInputStream()));
|
||||
else {
|
||||
result = new Pair<>(true, streamToString(connection.getInputStream()));
|
||||
}
|
||||
connection.disconnect();
|
||||
return result;
|
||||
}
|
||||
|
||||
private String streamToString(InputStream is) throws IOException {
|
||||
|
|
Loading…
Reference in a new issue