Commit c392dacf authored by Ricki Hirner's avatar Ricki Hirner

Follow redirects on DELETE, too

parent 1c86da6e
Pipeline #7408974 passed with stage
in 3 minutes and 59 seconds
......@@ -201,16 +201,25 @@ public class DavResourceTest {
rq = mockServer.takeRequest();
assertEquals("\"DeleteOnlyThisETag\"", rq.getHeader("If-Match"));
// 302 Moved Temporarily
mockServer.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP)
.setHeader("Location", "/new-location")
);
mockServer.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK));
dav.delete(null);
/* NEGATIVE TEST CASES */
// 302 Moved Temporarily
// 207 multi-status (e.g. single resource couldn't be deleted when DELETEing a collection)
mockServer.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP));
.setResponseCode(207));
try {
dav.delete(null);
fail();
} catch(HttpException e) {
// we don't follow redirects on DELETE
// treat 207 as an error
}
}
......@@ -223,14 +232,14 @@ public class DavResourceTest {
// test for non-multi-status responses:
// * 500 Internal Server Error
mockServer.enqueue(new MockResponse().setResponseCode(500));
mockServer.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_INTERNAL_ERROR));
try {
dav.propfind(0, ResourceType.NAME);
fail("Expected HttpException");
} catch(HttpException e) {
}
// * 200 OK (instead of 207 Multi-Status)
mockServer.enqueue(new MockResponse().setResponseCode(200));
mockServer.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_OK));
try {
dav.propfind(0, ResourceType.NAME);
fail("Expected InvalidDavResponseException");
......
......@@ -192,7 +192,6 @@ public class DavResource {
builder.header("If-None-Match", "*");
response = httpClient.newCall(builder.build()).execute();
if (response.isRedirect()) {
processRedirection(response);
redirected = true;
......@@ -216,14 +215,22 @@ public class DavResource {
* @throws HttpException on HTTP errors, including redirections
*/
public void delete(String ifMatchETag) throws IOException, HttpException {
Request.Builder builder = new Request.Builder()
.delete()
.url(location);
if (ifMatchETag != null)
builder.header("If-Match", QuotedStringUtils.asQuotedString(ifMatchETag));
Response response = httpClient.newCall(builder.build()).execute();
checkStatus(response, false);
Response response = null;
for (int attempt = 0; attempt < MAX_REDIRECTS; attempt++) {
Request.Builder builder = new Request.Builder()
.delete()
.url(location);
if (ifMatchETag != null)
builder.header("If-Match", QuotedStringUtils.asQuotedString(ifMatchETag));
response = httpClient.newCall(builder.build()).execute();
if (response.isRedirect()) {
processRedirection(response);
} else
break;
}
checkStatus(response, false);
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
......
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