Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COPY, MOVE: correctly set Overwrite header #40

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/main/kotlin/at/bitfire/dav4jvm/DavResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,21 @@ open class DavResource @JvmOverloads constructor(
* Updates [location] on success.
*
* @param destination where the resource shall be moved to
* @param forceOverride whether resources are overwritten when they already exist in destination
* @param overwrite whether resources are overwritten when they already exist in destination
*
* @throws IOException on I/O error
* @throws HttpException on HTTP error
* @throws DavException on WebDAV error or HTTPS -> HTTP redirect
*/
@Throws(IOException::class, HttpException::class, DavException::class)
fun move(destination: HttpUrl, forceOverride: Boolean, callback: ResponseCallback) {
fun move(destination: HttpUrl, overwrite: Boolean, callback: ResponseCallback) {
val requestBuilder = Request.Builder()
.method("MOVE", null)
.header("Content-Length", "0")
.header("Destination", destination.toString())

if (forceOverride) requestBuilder.header("Overwrite", "F")
if (!overwrite) // RFC 4918 9.9.3 and 10.6, default value: T
requestBuilder.header("Overwrite", "F")

followRedirects {
requestBuilder.url(location)
Expand Down Expand Up @@ -216,20 +217,21 @@ open class DavResource @JvmOverloads constructor(
* Sends a COPY request for this resource. Follows up to [MAX_REDIRECTS] redirects.
*
* @param destination where the resource shall be copied to
* @param forceOverride whether resources are overwritten when they already exist in destination
* @param overwrite whether resources are overwritten when they already exist in destination
*
* @throws IOException on I/O error
* @throws HttpException on HTTP error
* @throws DavException on WebDAV error or HTTPS -> HTTP redirect
*/
@Throws(IOException::class, HttpException::class, DavException::class)
fun copy(destination:HttpUrl, forceOverride: Boolean, callback: ResponseCallback) {
fun copy(destination:HttpUrl, overwrite: Boolean, callback: ResponseCallback) {
val requestBuilder = Request.Builder()
.method("COPY", null)
.header("Content-Length", "0")
.header("Destination", destination.toString())

if (forceOverride) requestBuilder.header("Overwrite", "F")
if (!overwrite) // RFC 4918 9.9.3 and 10.6, default value: T
requestBuilder.header("Overwrite", "F")

followRedirects {
requestBuilder.url(location)
Expand Down
8 changes: 4 additions & 4 deletions src/test/kotlin/at/bitfire/dav4jvm/DavResourceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DavResourceTest {
assertEquals("COPY", rq.method)
assertEquals(url.encodedPath, rq.path)
assertEquals(destination.toString(), rq.getHeader("Destination"))
assertNull(rq.getHeader("Overwrite"))
assertEquals("F", rq.getHeader("Overwrite"))

// no preconditions, 204 No content, resource successfully copied to a preexisting
// destination resource
Expand All @@ -95,7 +95,7 @@ class DavResourceTest {
assertEquals("COPY", rq.method)
assertEquals(url.encodedPath, rq.path)
assertEquals(destination.toString(), rq.getHeader("Destination"))
assertEquals("F", rq.getHeader("Overwrite"))
assertNull(rq.getHeader("Overwrite"))

/* NEGATIVE TEST CASES */

Expand Down Expand Up @@ -333,7 +333,7 @@ class DavResourceTest {
assertEquals("MOVE", rq.method)
assertEquals(url.encodedPath, rq.path)
assertEquals(destination.toString(), rq.getHeader("Destination"))
assertNull(rq.getHeader("Overwrite"))
assertEquals("F", rq.getHeader("Overwrite"))

// no preconditions, 204 No content, URL already mapped, overwrite
mockServer.enqueue(MockResponse()
Expand All @@ -351,7 +351,7 @@ class DavResourceTest {
assertEquals("MOVE", rq.method)
assertEquals(url.encodedPath, rq.path)
assertEquals(destination.toString(), rq.getHeader("Destination"))
assertEquals("F", rq.getHeader("Overwrite"))
assertNull(rq.getHeader("Overwrite"))

/* NEGATIVE TEST CASES */

Expand Down
Loading