Skip to content

Commit

Permalink
Request expiration in 3 days
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc2822 committed Nov 17, 2024
1 parent 29a03c9 commit e9c5a18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ data class Collection(
/** WebDAV-Push subscription URL */
var pushSubscription: String? = null,

/** when the [pushSubscription] expires (timestamp) */
/** when the [pushSubscription] expires (timestamp, used to determine whether we need to re-subscribe) */
var pushSubscriptionExpires: Long? = null,

/** when the [pushSubscription] was created/updated (timestamp, used to determine whether we need to re-subscribe) */
/** when the [pushSubscription] was created/updated (timestamp) */
var pushSubscriptionCreated: Long? = null

) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,25 @@ class PushRegistrationWorker @AssistedInject constructor(
.use { client ->
val httpClient = client.okHttpClient

// requested expiration time: 3 days
val requestedExpiration = Instant.now() + Duration.ofDays(3)

val serializer = XmlUtils.newSerializer()
val writer = StringWriter()
serializer.setOutput(writer)
serializer.startDocument("UTF-8", true)
serializer.insertTag(Property.Name(NS_WEBDAV_PUSH, "push-register")) {
serializer.insertTag(Property.Name(NS_WEBDAV_PUSH, "subscription")) {
// subscription URL
serializer.insertTag(Property.Name(NS_WEBDAV_PUSH, "web-push-subscription")) {
serializer.insertTag(Property.Name(NS_WEBDAV_PUSH, "push-resource")) {
text(endpoint)
}
}
// requested expiration
serializer.insertTag(Property.Name(NS_WEBDAV_PUSH, "expires")) {
text(HttpUtils.formatDate(requestedExpiration))
}
}
}
serializer.endDocument()
Expand All @@ -102,7 +110,7 @@ class PushRegistrationWorker @AssistedInject constructor(
val subscriptionUrl = response.header("Location")
val expires = response.header("Expires")?.let { expiresDate ->
HttpUtils.parseDate(expiresDate)
} ?: /* or assume 3 days */ (Instant.now() + Duration.ofDays(3))
} ?: /* or assume requested expiration */ requestedExpiration
collectionRepository.updatePushSubscription(collection.id, subscriptionUrl, expires?.epochSecond)
} else
logger.warning("Couldn't register push for ${collection.url}: $response")
Expand Down

0 comments on commit e9c5a18

Please sign in to comment.