Skip to content
Merged
Changes from 1 commit
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: 10 additions & 2 deletions app/src/main/java/at/bitfire/icsdroid/CalendarFetcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.ktor.client.request.basicAuth
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.statement.bodyAsChannel
import io.ktor.http.BadContentTypeFormatException
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpStatusCode
Expand Down Expand Up @@ -154,16 +155,23 @@ open class CalendarFetcher(
val statusCode = response.status
when {
// 20x
statusCode.isSuccess() ->
statusCode.isSuccess() -> {
val contentType: ContentType? = try {
response.contentType()
} catch (e: BadContentTypeFormatException) {
Log.w(Constants.TAG,"Failed to parse content type. Continuing without.", e)
null
}
onSuccess(
response.bodyAsChannel().toInputStream(),
response.contentType(),
contentType,
response.headers[HttpHeaders.ETag],
response.headers[HttpHeaders.LastModified]?.let {
HttpUtils.parseDate(it)?.time
},
null
)
}

// 30x
statusCode == HttpStatusCode.NotModified -> onNotModified()
Expand Down