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

Add optional headers to DavResource:mkCol() #46

Merged
merged 2 commits into from
Jun 10, 2024
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
15 changes: 10 additions & 5 deletions src/main/kotlin/at/bitfire/dav4jvm/DavResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,26 @@ open class DavResource @JvmOverloads constructor(
*
* @param xmlBody optional request body (used for MKCALENDAR or Extended MKCOL)
* @param method HTTP MKCOL method (`MKCOL` by default, may for instance be `MKCALENDAR`)
* @param headers additional headers to send with the request
* @param callback called for the response
*
* @throws IOException on I/O error
* @throws HttpException on HTTP error
* @throws DavException on HTTPS -> HTTP redirect
*/
@Throws(IOException::class, HttpException::class)
fun mkCol(xmlBody: String?, method: String = "MKCOL", callback: ResponseCallback) {
fun mkCol(xmlBody: String?, method: String = "MKCOL", headers: Headers? = null, callback: ResponseCallback) {
val rqBody = xmlBody?.toRequestBody(MIME_XML)

val request = Request.Builder()
.method(method, rqBody)
.url(UrlUtils.withTrailingSlash(location))

if (headers != null)
request.headers(headers)

followRedirects {
httpClient.newCall(Request.Builder()
.method(method, rqBody)
.url(UrlUtils.withTrailingSlash(location))
.build()).execute()
httpClient.newCall(request.build()).execute()
}.use { response ->
checkStatus(response)
callback.onResponse(response)
Expand Down