Commit 05322829 authored by Ricki Hirner's avatar Ricki Hirner

Always close response body streams

parent d3cb90c6
......@@ -109,6 +109,9 @@ public class DavResource {
for (String capability : HttpUtils.listHeader(response, "DAV"))
capabilities.add(capability.trim());
if (response.body() != null)
response.body().close();
}
public void mkCol(String xmlBody) throws IOException, HttpException {
......@@ -126,13 +129,16 @@ public class DavResource {
break;
}
checkStatus(response);
if (response.body() != null)
response.body().close();
}
/**
* Sends a GET request to the resource. Note that this method expects the server to
* return an ETag (which is required for CalDAV and CardDAV, but not for WebDAV in general).
* @param accept content of Accept header (must not be null, but may be */* )
* @return response body
* @return response body (has to be closed by caller)
* @throws DavException on WebDAV errors, or when the response doesn't contain an ETag
*/
public ResponseBody get(@NonNull String accept) throws IOException, HttpException, DavException {
......@@ -191,6 +197,7 @@ public class DavResource {
builder.header("If-None-Match", "*");
response = httpClient.newCall(builder.build()).execute();
if (response.isRedirect()) {
processRedirection(response);
redirected = true;
......@@ -199,6 +206,9 @@ public class DavResource {
}
checkStatus(response);
if (response.body() != null)
response.body().close();
String eTag = response.header("ETag");
if (TextUtils.isEmpty(eTag))
properties.remove(GetETag.NAME);
......@@ -222,6 +232,9 @@ public class DavResource {
Response response = httpClient.newCall(builder.build()).execute();
checkStatus(response);
if (response.body() != null)
response.body().close();
if (response.code() == 207) {
/* If an error occurs deleting a member resource (a resource other than
the resource identified in the Request-URI), then the response can be
......@@ -528,7 +541,7 @@ public class DavResource {
eventType = parser.next();
}
if (status != null && status.code/100 != 2)
if (prop != null && status != null && status.code/100 != 2)
// not successful, null out property values so that they can be removed when merging in parseMultiStatus_Response
prop.nullAllValues();
......
......@@ -5,9 +5,6 @@ import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
import java.text.SimpleDateFormat;
import java.util.Locale;
import lombok.SneakyThrows;
public class XmlUtils {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment