Fix MangaLib provider
This commit is contained in:
@@ -10,6 +10,7 @@ import org.junit.runners.Parameterized
|
||||
import org.koin.core.context.startKoin
|
||||
import org.koin.dsl.module
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.core.parser.UserAgentInterceptor
|
||||
import org.koitharu.kotatsu.core.prefs.SourceConfig
|
||||
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.domain.MangaProviderFactory
|
||||
@@ -88,6 +89,8 @@ class RemoteRepositoryTest(source: MangaSource) {
|
||||
module {
|
||||
factory {
|
||||
OkHttpClient.Builder()
|
||||
.cookieJar(TemporaryCookieJar())
|
||||
.addInterceptor(UserAgentInterceptor)
|
||||
.connectTimeout(20, TimeUnit.SECONDS)
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
.writeTimeout(20, TimeUnit.SECONDS)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.koitharu.kotatsu.parsers
|
||||
|
||||
import okhttp3.Cookie
|
||||
import okhttp3.CookieJar
|
||||
import okhttp3.HttpUrl
|
||||
import org.koitharu.kotatsu.core.local.cookies.cache.SetCookieCache
|
||||
|
||||
class TemporaryCookieJar : CookieJar {
|
||||
|
||||
private val cache = SetCookieCache()
|
||||
|
||||
override fun loadForRequest(url: HttpUrl): List<Cookie> {
|
||||
return cache.toList()
|
||||
}
|
||||
|
||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
||||
cache.addAll(cookies)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,33 @@
|
||||
package org.koitharu.kotatsu.utils
|
||||
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import org.junit.Assert
|
||||
import org.koin.core.KoinComponent
|
||||
import org.koin.core.inject
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
|
||||
object AssertX {
|
||||
object AssertX : KoinComponent {
|
||||
|
||||
private val okHttp by inject<OkHttpClient>()
|
||||
|
||||
fun assertContentType(url: String, vararg types: String) {
|
||||
Assert.assertFalse("URL is empty", url.isEmpty())
|
||||
val cn = URL(url).openConnection() as HttpURLConnection
|
||||
cn.requestMethod = "HEAD"
|
||||
cn.connect()
|
||||
when (val code = cn.responseCode) {
|
||||
HttpURLConnection.HTTP_MOVED_PERM,
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.head()
|
||||
.build()
|
||||
val response = okHttp.newCall(request).execute()
|
||||
when (val code = response.code) {
|
||||
/*HttpURLConnection.HTTP_MOVED_PERM,
|
||||
HttpURLConnection.HTTP_MOVED_TEMP -> {
|
||||
assertContentType(cn.getHeaderField("Location"), *types)
|
||||
}
|
||||
}*/
|
||||
HttpURLConnection.HTTP_OK -> {
|
||||
val ct = cn.contentType.substringBeforeLast(';').split("/")
|
||||
val type = response.body!!.contentType()
|
||||
Assert.assertTrue(types.any {
|
||||
val x = it.split('/')
|
||||
x[0] == ct[0] && (x[1] == "*" || x[1] == ct[1])
|
||||
type?.type == x[0] && (x[1] == "*" || type.subtype == x[1])
|
||||
})
|
||||
}
|
||||
else -> Assert.fail("Invalid response code $code at $url")
|
||||
|
||||
Reference in New Issue
Block a user