Commit 0e99ffde authored by Ricki Hirner's avatar Ricki Hirner 🐑
Browse files

DELETE: add If-Schedule-Tag-Match

parent 2579a454
Pipeline #161675868 passed with stages
in 1 minute and 55 seconds
......@@ -220,8 +220,8 @@ open class DavResource @JvmOverloads constructor(
* When the server returns an ETag, it is stored in response properties.
*
* @param body new resource body to upload
* @param ifMatch value of `If-Match` header to set, or null to omit
* @param ifScheduleTag value of `If-Schedule-Tag` header to set, or null to omit
* @param ifETag value of `If-Match` header to set, or null to omit
* @param ifScheduleTag value of `If-Schedule-Tag-Match` header to set, or null to omit
* @param ifNoneMatch indicates whether `If-None-Match: *` ("don't overwrite anything existing") header shall be sent
* @param callback called with server response unless an exception is thrown
*
......@@ -229,15 +229,15 @@ open class DavResource @JvmOverloads constructor(
* @throws HttpException on HTTP error
*/
@Throws(IOException::class, HttpException::class)
fun put(body: RequestBody, ifMatch: String? = null, ifScheduleTag: String? = null, ifNoneMatch: Boolean = false, callback: (Response) -> Unit) {
fun put(body: RequestBody, ifETag: String? = null, ifScheduleTag: String? = null, ifNoneMatch: Boolean = false, callback: (Response) -> Unit) {
followRedirects {
val builder = Request.Builder()
.put(body)
.url(location)
if (ifMatch != null)
if (ifETag != null)
// only overwrite specific version
builder.header("If-Match", QuotedStringUtils.asQuotedString(ifMatch))
builder.header("If-Match", QuotedStringUtils.asQuotedString(ifETag))
if (ifScheduleTag != null)
// only overwrite specific version
builder.header("If-Schedule-Tag-Match", QuotedStringUtils.asQuotedString(ifScheduleTag))
......@@ -258,21 +258,24 @@ open class DavResource @JvmOverloads constructor(
*
* Follows up to [MAX_REDIRECTS] redirects.
*
* @param ifMatchETag value of `If-Match` header to set, or null to omit
* @param callback called with server response unless an exception is thrown
* @param ifETag value of `If-Match` header to set, or null to omit
* @param ifScheduleTag value of `If-Schedule-Tag-Match` header to set, or null to omit
* @param callback called with server response unless an exception is thrown
*
* @throws IOException on I/O error
* @throws HttpException on HTTP errors, or when 207 Multi-Status is returned
* (because then there was probably a problem with a member resource)
*/
@Throws(IOException::class, HttpException::class)
fun delete(ifMatchETag: String?, callback: (Response) -> Unit) {
fun delete(ifETag: String? = null, ifScheduleTag: String? = null, callback: (Response) -> Unit) {
followRedirects {
val builder = Request.Builder()
.delete()
.url(location)
if (ifMatchETag != null)
builder.header("If-Match", QuotedStringUtils.asQuotedString(ifMatchETag))
if (ifETag != null)
builder.header("If-Match", QuotedStringUtils.asQuotedString(ifETag))
if (ifScheduleTag != null)
builder.header("If-Schedule-Tag-Match", QuotedStringUtils.asQuotedString(ifScheduleTag))
httpClient.newCall(builder.build()).execute()
}.use { response ->
......
......@@ -329,7 +329,7 @@ class DavResourceTest {
mockServer.enqueue(MockResponse()
.setResponseCode(HttpURLConnection.HTTP_NO_CONTENT))
var called = false
dav.delete(null) {
dav.delete {
called = true
}
assertTrue(called)
......@@ -339,18 +339,19 @@ class DavResourceTest {
assertEquals(url.encodedPath, rq.path)
assertNull(rq.getHeader("If-Match"))
// precondition: If-Match, 200 OK
// precondition: If-Match / If-Schedule-Tag-Match, 200 OK
mockServer.enqueue(MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody("Resource has been deleted."))
called = false
dav.delete("DeleteOnlyThisETag") {
dav.delete("DeleteOnlyThisETag", "DeleteOnlyThisScheduleTag") {
called = true
}
assertTrue(called)
rq = mockServer.takeRequest()
assertEquals("\"DeleteOnlyThisETag\"", rq.getHeader("If-Match"))
assertEquals("\"DeleteOnlyThisScheduleTag\"", rq.getHeader("If-Schedule-Tag-Match"))
// 302 Moved Temporarily
mockServer.enqueue(MockResponse()
......
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