Skip to content

Commit e22831f

Browse files
authored
Add possibility to follow redirects at options request (#76)
* Implement WebDAV detection via OPTIONS request with redirect support * Revert "Implement WebDAV detection via OPTIONS request with redirect support" This reverts commit 76d46a8. * Add support for following redirects in OPTIONS request * Rename call block
1 parent fda8229 commit e22831f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/kotlin/at/bitfire/dav4jvm/DavResource.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,30 @@ open class DavResource @JvmOverloads constructor(
151151

152152
/**
153153
* Sends an OPTIONS request to this resource without HTTP compression (because some servers have
154-
* broken compression for OPTIONS). Doesn't follow redirects.
154+
* broken compression for OPTIONS). Follows up to [MAX_REDIRECTS] redirects when set.
155155
*
156+
* @param followRedirects whether redirects should be followed (default: *false*)
156157
* @param callback called with server response unless an exception is thrown
157158
*
158159
* @throws IOException on I/O error
159160
* @throws HttpException on HTTP error
160161
* @throws DavException on HTTPS -> HTTP redirect
161162
*/
162163
@Throws(IOException::class, HttpException::class)
163-
fun options(callback: CapabilitiesCallback) {
164-
httpClient.newCall(Request.Builder()
164+
fun options(followRedirects: Boolean = false, callback: CapabilitiesCallback) {
165+
val requestOptions = {
166+
httpClient.newCall(Request.Builder()
165167
.method("OPTIONS", null)
166168
.header("Content-Length", "0")
167169
.url(location)
168170
.header("Accept-Encoding", "identity") // disable compression
169-
.build()).execute().use { response ->
171+
.build()).execute()
172+
}
173+
val response = if (followRedirects)
174+
followRedirects(requestOptions)
175+
else
176+
requestOptions()
177+
response.use {
170178
checkStatus(response)
171179
callback.onCapabilities(
172180
HttpUtils.listHeader(response, "DAV").map { it.trim() }.toSet(),

0 commit comments

Comments
 (0)