Fix content-type not being parsed when getting url rss type

This commit is contained in:
Shinokuni 2020-10-05 22:18:02 +02:00
parent eb58311040
commit ec53cbd683
2 changed files with 6 additions and 3 deletions

View File

@ -167,7 +167,7 @@ class LocalRSSDataSourceTest {
@Test
fun isUrlResourceSuccessfulTest() {
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
.addHeader("Content-Type", "application/atom+xml"))
.addHeader("Content-Type", "application/atom+xml; charset=UTF-8"))
assertTrue(localRSSDataSource.isUrlRSSResource(url.toString()))
}
@ -182,7 +182,7 @@ class LocalRSSDataSourceTest {
@Test
fun isUrlRSSResourceBadContentTypeTest() {
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
.addHeader("Content-Type", "application/xml")
.addHeader("Content-Type", "application/xml; charset=UTF-8")
.setBody("<html> </html>"))
assertFalse(localRSSDataSource.isUrlRSSResource(url.toString()))

View File

@ -73,7 +73,10 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) {
val response = queryUrl(url, null)
return if (response.isSuccessful) {
val contentType = response.header(LibUtils.CONTENT_TYPE_HEADER)
val header = response.header(LibUtils.CONTENT_TYPE_HEADER)
?: return false
val contentType = LibUtils.parseContentType(header)
?: return false
var type = LocalRSSHelper.getRSSType(contentType)