Skip to content

Add possibility to follow redirects at options request #76

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

Merged
merged 4 commits into from
Jul 24, 2025
Merged
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
16 changes: 12 additions & 4 deletions src/main/kotlin/at/bitfire/dav4jvm/DavResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,30 @@ 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
* @throws HttpException on HTTP error
* @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(),
Expand Down
Loading