File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
src/main/kotlin/at/bitfire/dav4jvm Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -151,22 +151,30 @@ open class DavResource @JvmOverloads constructor(
151
151
152
152
/* *
153
153
* 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 .
155
155
*
156
+ * @param followRedirects whether redirects should be followed (default: *false*)
156
157
* @param callback called with server response unless an exception is thrown
157
158
*
158
159
* @throws IOException on I/O error
159
160
* @throws HttpException on HTTP error
160
161
* @throws DavException on HTTPS -> HTTP redirect
161
162
*/
162
163
@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 callBlock = {
166
+ httpClient.newCall(Request .Builder ()
165
167
.method(" OPTIONS" , null )
166
168
.header(" Content-Length" , " 0" )
167
169
.url(location)
168
170
.header(" Accept-Encoding" , " identity" ) // disable compression
169
- .build()).execute().use { response ->
171
+ .build()).execute()
172
+ }
173
+ val response = if (followRedirects)
174
+ followRedirects(callBlock)
175
+ else
176
+ callBlock()
177
+ response.use {
170
178
checkStatus(response)
171
179
callback.onCapabilities(
172
180
HttpUtils .listHeader(response, " DAV" ).map { it.trim() }.toSet(),
You can’t perform that action at this time.
0 commit comments