Loading src/main/kotlin/at/bitfire/dav4jvm/DavResource.kt +13 −10 Original line number Diff line number Diff line Loading @@ -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 * Loading @@ -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)) Loading @@ -258,7 +258,8 @@ 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 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 Loading @@ -266,13 +267,15 @@ open class DavResource @JvmOverloads constructor( * (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 -> Loading src/test/kotlin/at/bitfire/dav4jvm/DavResourceTest.kt +4 −3 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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() Loading Loading
src/main/kotlin/at/bitfire/dav4jvm/DavResource.kt +13 −10 Original line number Diff line number Diff line Loading @@ -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 * Loading @@ -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)) Loading @@ -258,7 +258,8 @@ 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 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 Loading @@ -266,13 +267,15 @@ open class DavResource @JvmOverloads constructor( * (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 -> Loading
src/test/kotlin/at/bitfire/dav4jvm/DavResourceTest.kt +4 −3 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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() Loading