Skip to content

Commit

Permalink
Revert "Add selective interception. (#279)"
Browse files Browse the repository at this point in the history
This reverts commit d14ed64.
  • Loading branch information
cortinico committed Apr 4, 2020
1 parent a209c1e commit 19e917a
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 179 deletions.
24 changes: 0 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 0 additions & 7 deletions library-no-op/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

This file was deleted.

3 changes: 0 additions & 3 deletions library/src/main/java/com/chuckerteam/chucker/api/Chucker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 19e917a

Please sign in to comment.