diff --git a/src/main/kotlin/at/bitfire/dav4jvm/DavResource.kt b/src/main/kotlin/at/bitfire/dav4jvm/DavResource.kt index b0c5204..25a94bb 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/DavResource.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/DavResource.kt @@ -151,8 +151,9 @@ open class DavResource @JvmOverloads constructor( /** * Sends an OPTIONS request to this resource without HTTP compression (because some servers have - * broken compression for OPTIONS). Doesn't follow redirects. + * broken compression for OPTIONS). Follows up to [MAX_REDIRECTS] redirects when set. * + * @param followRedirects whether redirects should be followed (default: *false*) * @param callback called with server response unless an exception is thrown * * @throws IOException on I/O error @@ -160,13 +161,20 @@ open class DavResource @JvmOverloads constructor( * @throws DavException on HTTPS -> HTTP redirect */ @Throws(IOException::class, HttpException::class) - fun options(callback: CapabilitiesCallback) { - httpClient.newCall(Request.Builder() + fun options(followRedirects: Boolean = false, callback: CapabilitiesCallback) { + val requestOptions = { + httpClient.newCall(Request.Builder() .method("OPTIONS", null) .header("Content-Length", "0") .url(location) .header("Accept-Encoding", "identity") // disable compression - .build()).execute().use { response -> + .build()).execute() + } + val response = if (followRedirects) + followRedirects(requestOptions) + else + requestOptions() + response.use { checkStatus(response) callback.onCapabilities( HttpUtils.listHeader(response, "DAV").map { it.trim() }.toSet(),