diff --git a/README.md b/README.md index 24d06834b..866b3f9d2 100644 --- a/README.md +++ b/README.md @@ -129,30 +129,6 @@ You can redact headers that contain sensitive information by calling `redactHead interceptor.redactHeader("Auth-Token", "User-Session"); ``` -### Skip-Inspection ️🕵️ - -If you need to selectively skip Chucker inspection on some endpoints or on particular requests you can add a special header - `Skip-Chucker-Interceptor: true`. This will inform Chucker to not process this request. Chucker will also strip this header from any request before sending it to a server. - -If you use `OkHttp` directly, create requests like below. - -```kotlin -val request = Request.Builder().url(serverUrl) - .addHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME, "true") - .build() - -client.newCall(request).execute() -``` - -If you are a `Retrofit` user you can configure it per endpoint like this. - -```kotlin -fun Service { - @GET("/") - @Headers(Chucker.SKIP_INTERCEPTOR_HEADER) - fun networkRequest(): Unit -} -``` - ## Migrating 🚗 If you're migrating **from [Chuck](https://github.com/jgilfelt/chuck) to Chucker**, please refer to this [migration guide](/docs/migrating-from-chuck.md). diff --git a/library-no-op/build.gradle b/library-no-op/build.gradle index 141a21864..8951aa811 100644 --- a/library-no-op/build.gradle +++ b/library-no-op/build.gradle @@ -25,13 +25,6 @@ artifacts { dependencies { implementation "com.squareup.okhttp3:okhttp:$okhttp3Version" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" - - testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" - testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion" - testImplementation "io.mockk:mockk:$mockkVersion" - testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp3Version" - testImplementation "com.google.truth:truth:$truthVersion" } apply from: rootProject.file('gradle/gradle-mvn-push.gradle') diff --git a/library-no-op/src/main/java/com/chuckerteam/chucker/api/Chucker.kt b/library-no-op/src/main/java/com/chuckerteam/chucker/api/Chucker.kt index 8328c1bd3..3476165ab 100644 --- a/library-no-op/src/main/java/com/chuckerteam/chucker/api/Chucker.kt +++ b/library-no-op/src/main/java/com/chuckerteam/chucker/api/Chucker.kt @@ -11,9 +11,6 @@ object Chucker { const val SCREEN_HTTP = 1 const val SCREEN_ERROR = 2 - const val SKIP_INTERCEPTOR_HEADER_NAME = "Skip-Chucker-Interceptor" - const val SKIP_INTERCEPTOR_HEADER = "$SKIP_INTERCEPTOR_HEADER_NAME: true" - @Suppress("MayBeConst ") // https://github.com/ChuckerTeam/chucker/pull/169#discussion_r362341353 val isOp = false diff --git a/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt b/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt index 465911d2a..537691a64 100644 --- a/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt +++ b/library-no-op/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt @@ -21,9 +21,7 @@ class ChuckerInterceptor @JvmOverloads constructor( @Throws(IOException::class) override fun intercept(chain: Interceptor.Chain): Response { - val request = chain.request().newBuilder() - .removeHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME) - .build() + val request = chain.request() return chain.proceed(request) } } diff --git a/library-no-op/src/test/java/com/chuckerteam/chucker/api/ChuckerInterceptorTest.kt b/library-no-op/src/test/java/com/chuckerteam/chucker/api/ChuckerInterceptorTest.kt deleted file mode 100644 index ae0611e10..000000000 --- a/library-no-op/src/test/java/com/chuckerteam/chucker/api/ChuckerInterceptorTest.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.chuckerteam.chucker.api - -import android.content.Context -import com.google.common.truth.Truth.assertThat -import io.mockk.mockk -import okhttp3.OkHttpClient -import okhttp3.Request -import okhttp3.mockwebserver.MockResponse -import okhttp3.mockwebserver.MockWebServer -import org.junit.Rule -import org.junit.jupiter.api.Test - -class ChuckerInterceptorTest { - @get:Rule val server = MockWebServer() - private val serverUrl = server.url("/") // Starts server implicitly - private val mockContext = mockk() - private val client = OkHttpClient.Builder() - .addInterceptor(ChuckerInterceptor(mockContext)) - .build() - - @Test - fun skipChuckerHeader_isNotAvailableForTheServerRequest() { - server.enqueue(MockResponse().setBody("Hello, world!")) - val request = Request.Builder().url(serverUrl) - .addHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME, "true") - .build() - - val response = client.newCall(request).execute() - - assertThat(response.request().header(Chucker.SKIP_INTERCEPTOR_HEADER_NAME)).isNull() - } - - @Test - fun doNotSkipChuckerHeader_isNotAvailableForTheServerRequest() { - server.enqueue(MockResponse().setBody("Hello, world!")) - val request = Request.Builder().url(serverUrl) - .addHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME, "false") - .build() - - val response = client.newCall(request).execute() - - assertThat(response.request().header(Chucker.SKIP_INTERCEPTOR_HEADER_NAME)).isNull() - } -} diff --git a/library/src/main/java/com/chuckerteam/chucker/api/Chucker.kt b/library/src/main/java/com/chuckerteam/chucker/api/Chucker.kt index 5d482232b..203d15003 100644 --- a/library/src/main/java/com/chuckerteam/chucker/api/Chucker.kt +++ b/library/src/main/java/com/chuckerteam/chucker/api/Chucker.kt @@ -15,9 +15,6 @@ object Chucker { const val SCREEN_HTTP = 1 const val SCREEN_ERROR = 2 - const val SKIP_INTERCEPTOR_HEADER_NAME = "Skip-Chucker-Interceptor" - const val SKIP_INTERCEPTOR_HEADER = "$SKIP_INTERCEPTOR_HEADER_NAME: true" - /** * Check if this instance is the operation one or no-op. * @return `true` if this is the operation instance. diff --git a/library/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt b/library/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt index f9de61888..24f41b441 100755 --- a/library/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt +++ b/library/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt @@ -74,14 +74,7 @@ class ChuckerInterceptor internal constructor( @Throws(IOException::class) override fun intercept(chain: Interceptor.Chain): Response { - val request = chain.request().newBuilder() - .removeHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME) - .build() - - if (chain.request().header(Chucker.SKIP_INTERCEPTOR_HEADER_NAME)?.toBoolean() == true) { - return chain.proceed(request) - } - + val request = chain.request() val response: Response val transaction = HttpTransaction() diff --git a/library/src/test/java/com/chuckerteam/chucker/api/ChuckerInterceptorTest.kt b/library/src/test/java/com/chuckerteam/chucker/api/ChuckerInterceptorTest.kt index b75f74ccf..648e47fbe 100644 --- a/library/src/test/java/com/chuckerteam/chucker/api/ChuckerInterceptorTest.kt +++ b/library/src/test/java/com/chuckerteam/chucker/api/ChuckerInterceptorTest.kt @@ -118,93 +118,6 @@ class ChuckerInterceptorTest { assertThat(responseBody.utf8()).isEqualTo("Hello, world!") } - @ParameterizedTest - @EnumSource(value = ClientFactory::class) - fun requestThatShouldBeSkipped_isNotProcessedByChucker(factory: ClientFactory) { - server.enqueue(MockResponse().setBody("Hello, world!")) - val request = Request.Builder().url(serverUrl) - .addHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME, "true") - .build() - - val client = factory.create(chuckerInterceptor) - client.newCall(request).execute().readByteStringBody() - - chuckerInterceptor.expectNoTransactions() - } - - @ParameterizedTest - @EnumSource(value = ClientFactory::class) - fun requestThatShouldBeSkipped_isDeliveredToTheEndConsumer(factory: ClientFactory) { - server.enqueue(MockResponse().setBody("Hello, world!")) - val request = Request.Builder().url(serverUrl) - .addHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME, "true") - .build() - - val client = factory.create(chuckerInterceptor) - val body = client.newCall(request).execute().body()!!.string() - - assertThat(body).isEqualTo("Hello, world!") - } - - @ParameterizedTest - @EnumSource(value = ClientFactory::class) - fun requestThatShouldNotBeSkipped_isProcessedByChucker(factory: ClientFactory) { - server.enqueue(MockResponse().setBody("Hello, world!")) - val request = Request.Builder().url(serverUrl) - .addHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME, "false") - .build() - - val client = factory.create(chuckerInterceptor) - client.newCall(request).execute().readByteStringBody() - val transaction = chuckerInterceptor.expectTransaction() - - assertThat(transaction.responseBody).isEqualTo("Hello, world!") - } - - @ParameterizedTest - @EnumSource(value = ClientFactory::class) - fun requestThatShouldNotBeSkipped_isDeliveredToTheEndConsumer(factory: ClientFactory) { - server.enqueue(MockResponse().setBody("Hello, world!")) - val request = Request.Builder().url(serverUrl) - .addHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME, "false") - .build() - - val client = factory.create(chuckerInterceptor) - val body = client.newCall(request).execute().body()!!.string() - - assertThat(body).isEqualTo("Hello, world!") - } - - @ParameterizedTest - @EnumSource(value = ClientFactory::class) - fun skipChuckerHeader_isNotAvailableForTheServerRequest(factory: ClientFactory) { - server.enqueue(MockResponse().setBody("Hello, world!")) - val request = Request.Builder().url(serverUrl) - .addHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME, "true") - .build() - - val client = factory.create(chuckerInterceptor) - var response = client.newCall(request).execute() - if (factory == ClientFactory.NETWORK) response = response.networkResponse()!! - - assertThat(response.request().header(Chucker.SKIP_INTERCEPTOR_HEADER_NAME)).isNull() - } - - @ParameterizedTest - @EnumSource(value = ClientFactory::class) - fun doNotSkipChuckerHeader_isNotAvailableForTheServerRequest(factory: ClientFactory) { - server.enqueue(MockResponse().setBody("Hello, world!")) - val request = Request.Builder().url(serverUrl) - .addHeader(Chucker.SKIP_INTERCEPTOR_HEADER_NAME, "false") - .build() - - val client = factory.create(chuckerInterceptor) - var response = client.newCall(request).execute() - if (factory == ClientFactory.NETWORK) response = response.networkResponse()!! - - assertThat(response.request().header(Chucker.SKIP_INTERCEPTOR_HEADER_NAME)).isNull() - } - @ParameterizedTest @EnumSource(value = ClientFactory::class) fun gzippedBody_withNoContent_isTransparentForChucker(factory: ClientFactory) {