From c3b1556816d889e81d95e5a21df5a4e3f907da57 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 6 Feb 2023 17:50:44 +0200 Subject: [PATCH] Add headers to CloudFlareException --- .../parsers/exception/CloudFlareProtectedException.kt | 2 ++ .../org/koitharu/kotatsu/parsers/CloudFlareInterceptor.kt | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/CloudFlareProtectedException.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/CloudFlareProtectedException.kt index 75337a12..e06415e3 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/CloudFlareProtectedException.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/CloudFlareProtectedException.kt @@ -1,7 +1,9 @@ package org.koitharu.kotatsu.parsers.exception +import okhttp3.Headers import okio.IOException class CloudFlareProtectedException( val url: String, + val headers: Headers, ) : IOException("Protected by CloudFlare: $url") \ 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 5f9a64c3..957eb889 100644 --- a/src/test/kotlin/org/koitharu/kotatsu/parsers/CloudFlareInterceptor.kt +++ b/src/test/kotlin/org/koitharu/kotatsu/parsers/CloudFlareInterceptor.kt @@ -13,11 +13,15 @@ private const val SERVER_CLOUDFLARE = "cloudflare" class CloudFlareInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { - val response = chain.proceed(chain.request()) + val request = chain.request() + val response = chain.proceed(request) if (response.code == HTTP_FORBIDDEN || response.code == HTTP_UNAVAILABLE) { if (response.header(HEADER_SERVER)?.startsWith(SERVER_CLOUDFLARE) == true) { response.closeQuietly() - throw CloudFlareProtectedException(response.request.url.toString()) + throw CloudFlareProtectedException( + url = response.request.url.toString(), + headers = request.headers, + ) } } return response