Move CloudFlareProtectedException to test sources
This commit is contained in:
@@ -57,7 +57,7 @@
|
|||||||
data-bs-toggle="modal" style="cursor: pointer;">
|
data-bs-toggle="modal" style="cursor: pointer;">
|
||||||
<i data-feather="power"></i>
|
<i data-feather="power"></i>
|
||||||
</td>
|
</td>
|
||||||
{% elseif case.failure.type == 'org.koitharu.kotatsu.parsers.exception.CloudFlareProtectedException' %}
|
{% elseif case.failure.type == 'org.koitharu.kotatsu.parsers.CloudFlareProtectedException' %}
|
||||||
<td class="table-secondary text-center" data-bs-target="#failure_{{ case.hashCode }}"
|
<td class="table-secondary text-center" data-bs-target="#failure_{{ case.hashCode }}"
|
||||||
data-bs-toggle="modal" style="cursor: pointer;">
|
data-bs-toggle="modal" style="cursor: pointer;">
|
||||||
<i data-feather="shield"></i>
|
<i data-feather="shield"></i>
|
||||||
@@ -101,29 +101,6 @@
|
|||||||
feather.replace()
|
feather.replace()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.koitharu.kotatsu.parsers
|
|||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okhttp3.internal.closeQuietly
|
import okhttp3.internal.closeQuietly
|
||||||
import org.koitharu.kotatsu.parsers.exception.CloudFlareProtectedException
|
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
|
|
||||||
private const val HEADER_SERVER = "Server"
|
private const val HEADER_SERVER = "Server"
|
||||||
@@ -11,18 +10,18 @@ private const val SERVER_CLOUDFLARE = "cloudflare"
|
|||||||
|
|
||||||
internal class CloudFlareInterceptor : Interceptor {
|
internal class CloudFlareInterceptor : Interceptor {
|
||||||
|
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
val request = chain.request()
|
val request = chain.request()
|
||||||
val response = chain.proceed(request)
|
val response = chain.proceed(request)
|
||||||
if (response.code == HttpURLConnection.HTTP_FORBIDDEN || response.code == HttpURLConnection.HTTP_UNAVAILABLE) {
|
if (response.code == HttpURLConnection.HTTP_FORBIDDEN || response.code == HttpURLConnection.HTTP_UNAVAILABLE) {
|
||||||
if (response.header(HEADER_SERVER)?.startsWith(SERVER_CLOUDFLARE) == true) {
|
if (response.header(HEADER_SERVER)?.startsWith(SERVER_CLOUDFLARE) == true) {
|
||||||
response.closeQuietly()
|
response.closeQuietly()
|
||||||
throw CloudFlareProtectedException(
|
throw CloudFlareProtectedException(
|
||||||
url = response.request.url.toString(),
|
url = response.request.url.toString(),
|
||||||
headers = request.headers,
|
headers = request.headers,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.koitharu.kotatsu.parsers.exception
|
package org.koitharu.kotatsu.parsers
|
||||||
|
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
@@ -6,4 +6,4 @@ import okio.IOException
|
|||||||
class CloudFlareProtectedException(
|
class CloudFlareProtectedException(
|
||||||
val url: String,
|
val url: String,
|
||||||
val headers: Headers,
|
val headers: Headers,
|
||||||
) : IOException("Protected by CloudFlare: $url")
|
) : IOException("Protected by CloudFlare: $url")
|
||||||
Reference in New Issue
Block a user