Skip to content

Commit 9c968ef

Browse files
committed
Allow malformed MIME types: ignore BadContentTypeFormatExceptions
When fetching calendar data, if the server responds with a malformed MIME type in the Content-Type header, we now log a warning and proceed without a content type instead of failing with error message.
1 parent 917641b commit 9c968ef

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

app/src/main/java/at/bitfire/icsdroid/CalendarFetcher.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import io.ktor.client.request.basicAuth
1515
import io.ktor.client.request.get
1616
import io.ktor.client.request.header
1717
import io.ktor.client.statement.bodyAsChannel
18+
import io.ktor.http.BadContentTypeFormatException
1819
import io.ktor.http.ContentType
1920
import io.ktor.http.HttpHeaders
2021
import io.ktor.http.HttpStatusCode
@@ -154,16 +155,23 @@ open class CalendarFetcher(
154155
val statusCode = response.status
155156
when {
156157
// 20x
157-
statusCode.isSuccess() ->
158+
statusCode.isSuccess() -> {
159+
val contentType: ContentType? = try {
160+
response.contentType()
161+
} catch (e: BadContentTypeFormatException) {
162+
Log.w(Constants.TAG,"Failed to parse content type. Continuing without.", e)
163+
null
164+
}
158165
onSuccess(
159166
response.bodyAsChannel().toInputStream(),
160-
response.contentType(),
167+
contentType,
161168
response.headers[HttpHeaders.ETag],
162169
response.headers[HttpHeaders.LastModified]?.let {
163170
HttpUtils.parseDate(it)?.time
164171
},
165172
null
166173
)
174+
}
167175

168176
// 30x
169177
statusCode == HttpStatusCode.NotModified -> onNotModified()

0 commit comments

Comments
 (0)