Skip to content

Commit

Permalink
Add optional headers to DavResource:mkCol() (#46)
Browse files Browse the repository at this point in the history
* Add optional headers to DavResource:mkCol()

Signed-off-by: ZetaTom <[email protected]>

* Reduce indentation

Signed-off-by: ZetaTom <[email protected]>

---------

Signed-off-by: ZetaTom <[email protected]>
  • Loading branch information
ZetaTom authored Jun 10, 2024
1 parent b87d772 commit ffdfc56
Showing 1 changed file with 10 additions and 5 deletions.
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

0 comments on commit ffdfc56

Please sign in to comment.