From d24ab347cbe18c30268203197659576ef1c60d0b Mon Sep 17 00:00:00 2001 From: Koitharu Date: Fri, 28 Jul 2023 14:35:13 +0300 Subject: [PATCH] Move CloudFlareProtectedException to test sources --- buildSrc/src/main/resources/report.html | 27 ++--------------- .../kotatsu/parsers/CloudFlareInterceptor.kt | 29 +++++++++---------- .../parsers}/CloudFlareProtectedException.kt | 4 +-- 3 files changed, 18 insertions(+), 42 deletions(-) rename src/{main/kotlin/org/koitharu/kotatsu/parsers/exception => test/kotlin/org/koitharu/kotatsu/parsers}/CloudFlareProtectedException.kt (57%) diff --git a/buildSrc/src/main/resources/report.html b/buildSrc/src/main/resources/report.html index b18a0dad..d297533e 100644 --- a/buildSrc/src/main/resources/report.html +++ b/buildSrc/src/main/resources/report.html @@ -57,7 +57,7 @@ data-bs-toggle="modal" style="cursor: pointer;"> - {% elseif case.failure.type == 'org.koitharu.kotatsu.parsers.exception.CloudFlareProtectedException' %} + {% elseif case.failure.type == 'org.koitharu.kotatsu.parsers.CloudFlareProtectedException' %} @@ -101,29 +101,6 @@ feather.replace() - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/src/test/kotlin/org/koitharu/kotatsu/parsers/CloudFlareInterceptor.kt b/src/test/kotlin/org/koitharu/kotatsu/parsers/CloudFlareInterceptor.kt index 8878779d..7d106750 100644 --- a/src/test/kotlin/org/koitharu/kotatsu/parsers/CloudFlareInterceptor.kt +++ b/src/test/kotlin/org/koitharu/kotatsu/parsers/CloudFlareInterceptor.kt @@ -3,7 +3,6 @@ package org.koitharu.kotatsu.parsers import okhttp3.Interceptor import okhttp3.Response import okhttp3.internal.closeQuietly -import org.koitharu.kotatsu.parsers.exception.CloudFlareProtectedException import java.net.HttpURLConnection private const val HEADER_SERVER = "Server" @@ -11,18 +10,18 @@ private const val SERVER_CLOUDFLARE = "cloudflare" internal class CloudFlareInterceptor : Interceptor { - override fun intercept(chain: Interceptor.Chain): Response { - val request = chain.request() - val response = chain.proceed(request) - if (response.code == HttpURLConnection.HTTP_FORBIDDEN || response.code == HttpURLConnection.HTTP_UNAVAILABLE) { - if (response.header(HEADER_SERVER)?.startsWith(SERVER_CLOUDFLARE) == true) { - response.closeQuietly() - throw CloudFlareProtectedException( - url = response.request.url.toString(), - headers = request.headers, - ) - } - } - return response - } + override fun intercept(chain: Interceptor.Chain): Response { + val request = chain.request() + val response = chain.proceed(request) + if (response.code == HttpURLConnection.HTTP_FORBIDDEN || response.code == HttpURLConnection.HTTP_UNAVAILABLE) { + if (response.header(HEADER_SERVER)?.startsWith(SERVER_CLOUDFLARE) == true) { + response.closeQuietly() + throw CloudFlareProtectedException( + url = response.request.url.toString(), + headers = request.headers, + ) + } + } + return response + } } diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/CloudFlareProtectedException.kt b/src/test/kotlin/org/koitharu/kotatsu/parsers/CloudFlareProtectedException.kt similarity index 57% rename from src/main/kotlin/org/koitharu/kotatsu/parsers/exception/CloudFlareProtectedException.kt rename to src/test/kotlin/org/koitharu/kotatsu/parsers/CloudFlareProtectedException.kt index e06415e3..bbfdae8a 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/CloudFlareProtectedException.kt +++ b/src/test/kotlin/org/koitharu/kotatsu/parsers/CloudFlareProtectedException.kt @@ -1,4 +1,4 @@ -package org.koitharu.kotatsu.parsers.exception +package org.koitharu.kotatsu.parsers import okhttp3.Headers import okio.IOException @@ -6,4 +6,4 @@ import okio.IOException class CloudFlareProtectedException( val url: String, val headers: Headers, -) : IOException("Protected by CloudFlare: $url") \ No newline at end of file +) : IOException("Protected by CloudFlare: $url")