From 6b11237e7c44bbfec4a2abf7aabb54d3eb060e94 Mon Sep 17 00:00:00 2001 From: Youssef Essam Date: Wed, 1 Jan 2025 12:04:01 +0200 Subject: [PATCH] Refactor `addPlutoKtorInterceptor` to improve URL handling - Replaced direct mutation of `requestUnBuilt.url` with a conditional check to ensure the URL is only updated if necessary. - Ensured proper handling of the actual or mock request URL in the interceptor logic. --- .../kotlin/com/pluto/plugins/network/ktor/PlutoKtorHelper.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pluto-plugins/plugins/network/interceptor-ktor/lib/src/main/kotlin/com/pluto/plugins/network/ktor/PlutoKtorHelper.kt b/pluto-plugins/plugins/network/interceptor-ktor/lib/src/main/kotlin/com/pluto/plugins/network/ktor/PlutoKtorHelper.kt index 542a995e..c5d12b90 100644 --- a/pluto-plugins/plugins/network/interceptor-ktor/lib/src/main/kotlin/com/pluto/plugins/network/ktor/PlutoKtorHelper.kt +++ b/pluto-plugins/plugins/network/interceptor-ktor/lib/src/main/kotlin/com/pluto/plugins/network/ktor/PlutoKtorHelper.kt @@ -21,7 +21,10 @@ fun HttpClient.addPlutoKtorInterceptor() { val request = requestUnBuilt.build() val networkInterceptor = NetworkInterceptor.intercept(request.convert(), NetworkInterceptor.Option(NAME)) val callResult = try { - requestUnBuilt.url(networkInterceptor.actualOrMockRequestUrl) + val actualOrMockRequestUrl = networkInterceptor.actualOrMockRequestUrl + if (requestUnBuilt.url.buildString() != actualOrMockRequestUrl) { + requestUnBuilt.url(actualOrMockRequestUrl) + } execute(requestUnBuilt) } catch (e: IOException) { networkInterceptor.onError(e)