Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ For questions, suggestions etc. use [Github discussions](https://github.com/bitf
We're happy about contributions, but please let us know in the discussions before. Then make the changes
in your own repository and send a pull request.

> [!NOTE]
> dav4jvm is currently being rewritten to use ktor instead of OkHttp to allow Kotlin Multiplatform support, and other engines.
>
> In the mean time, there are two packages available:
> - `at.bitfire.dav4jvm.okhttp` (the current one, using OkHttp, JVM only)
> - `io.github.mcdjuady.ktor` (new package, uses ktor, supports Kotlin Multiplatform)
>
> There's some common code shared between both packages, **and we cannot guarantee** that all of it is excluded from cross-dependencies (generic code using ktor-specific functions).
> The usages are most likely indicated in the kdoc, but something might be missing.
>
> Take this into consideration if you are going to exclude the ktor dependency on your project.


## Installation

Expand Down
25 changes: 25 additions & 0 deletions src/main/kotlin/at/bitfire/dav4jvm/HttpHeaderNames.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package at.bitfire.dav4jvm

object HttpHeaderNames {
/** [RFC4229 Section-2.1.2](https://datatracker.ietf.org/doc/html/rfc4229#section-2.1.2) */
const val Accept: String = "Accept"

/** [RFC4229 Section-2.1.5](https://datatracker.ietf.org/doc/html/rfc4229#section-2.1.5) */
const val AcceptEncoding: String = "Accept-Encoding"

/** [RFC4229 Section-2.1.45](https://datatracker.ietf.org/doc/html/rfc4229#section-2.1.45) */
const val ETag: String = "ETag"

/** [RFC6638 Section-8.2](https://datatracker.ietf.org/doc/html/rfc6638#section-8.2) */
const val ScheduleTag: String = "Schedule-Tag"
}
2 changes: 2 additions & 0 deletions src/main/kotlin/at/bitfire/dav4jvm/XmlReader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class XmlReader(
* Processes all the tags named [tagName], and sends every tag that has the [CONTENT_TYPE]
* attribute with [onNewType].
*
* **Requires Ktor.**
*
* @param tagName The name of the tag that contains the [CONTENT_TYPE] attribute value.
* @param onNewType Called every time a new [ContentType] is found.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@

package at.bitfire.dav4jvm.property.caldav

import at.bitfire.dav4jvm.HttpHeaderNames
import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.QuotedStringUtils
import at.bitfire.dav4jvm.XmlReader
import at.bitfire.dav4jvm.property.webdav.GetETag
import io.ktor.client.statement.HttpResponse
import io.ktor.http.HttpHeaders
import okhttp3.Response
import org.xmlpull.v1.XmlPullParser

Expand All @@ -29,11 +28,16 @@ data class ScheduleTag(
@JvmField
val NAME = Property.Name(NS_CALDAV, "schedule-tag")

/**
* Creates a [ScheduleTag] from an HTTP response's `Schedule-Tag` header.
*
* **Requires Ktor.**
*/
fun fromHttpResponse(response: HttpResponse) =
response.headers[HttpHeaders.ScheduleTag]?.let { ScheduleTag(it) }
response.headers[HttpHeaderNames.ScheduleTag]?.let { ScheduleTag(it) }

fun fromResponse(response: Response) =
response.header(HttpHeaders.ScheduleTag)?.let { ScheduleTag(it) }
response.header(HttpHeaderNames.ScheduleTag)?.let { ScheduleTag(it) }

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ data class SupportedCalendarData(

}

/**
* Checks whether the supported calendar data includes JCal (application/calendar+json).
*
* **Requires Ktor.**
*/
fun hasJCal() = types
.map { ContentType.parse(it) }
.any { ContentType.Application.contains(it) && "calendar+json".equals(it.contentSubtype, true) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,20 @@ class SupportedAddressData(

}

/**
* Checks whether the supported address data includes vCard 4.0 (`text/vcard; version=4.0`).
*
* **Requires Ktor.**
*/
fun hasVCard4() = types
.map { try { ContentType.parse(it) } catch (_: Exception) { ContentType.Any } }
.any { "text/vcard; version=4.0".equals(it.toString(), true) }

/**
* Checks whether the supported address data includes JCard (`application/vcard+json`).
*
* **Requires Ktor.**
*/
fun hasJCard() = types
.map { try { ContentType.parse(it) } catch (_: Exception) { ContentType.Any } }
.any { ContentType.Application.contains(it) && "vcard+json".equals(it.contentSubtype, true) }
Expand Down
11 changes: 8 additions & 3 deletions src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetETag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

package at.bitfire.dav4jvm.property.webdav

import at.bitfire.dav4jvm.HttpHeaderNames
import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.QuotedStringUtils
import at.bitfire.dav4jvm.XmlReader
import io.ktor.client.statement.HttpResponse
import io.ktor.http.HttpHeaders
import okhttp3.Response
import org.xmlpull.v1.XmlPullParser

Expand All @@ -33,11 +33,16 @@ data class GetETag(
@JvmField
val NAME = Property.Name(NS_WEBDAV, "getetag")

/**
* Creates a [GetETag] from an HTTP response's `ETag` header.
*
* **Requires Ktor.**
*/
fun fromHttpResponse(response: HttpResponse) =
response.headers[HttpHeaders.ETag]?.let { GetETag(it) }
response.headers[HttpHeaderNames.ETag]?.let { GetETag(it) }

fun fromResponse(response: Response) =
response.header("ETag")?.let { GetETag(it) }
response.header(HttpHeaderNames.ETag)?.let { GetETag(it) }
}

/**
Expand Down