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 1 commit
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
requestBuilder.header("Overwrite", "T")
rfc2822 marked this conversation as resolved.
Show resolved Hide resolved

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)
requestBuilder.header("Overwrite", "T")

followRedirects {
requestBuilder.url(location)
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/at/bitfire/dav4jvm/DavResourceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
assertEquals("T", rq.getHeader("Overwrite"))

/* NEGATIVE TEST CASES */

Expand Down Expand Up @@ -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"))
assertEquals("T", rq.getHeader("Overwrite"))

/* NEGATIVE TEST CASES */

Expand Down
Loading