Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/response body #205

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create response copy for processing
vbuberen committed Jan 24, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 99d3ae5b0742a67d263de33e4a4984edc35c8da3
Original file line number Diff line number Diff line change
@@ -47,24 +47,27 @@ class ChuckerInterceptor @JvmOverloads constructor(
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val response: Response
val originalResponse: Response
val transaction = HttpTransaction()

processRequest(request, transaction)
collector.onRequestSent(transaction)

try {
response = chain.proceed(request)
originalResponse = chain.proceed(request)
} catch (e: IOException) {
transaction.error = e.toString()
collector.onResponseReceived(transaction)
throw e
}

processResponse(response, transaction)
// Creating a copy of response to avoid problems with multiple interceptors
val responseCopy = originalResponse.newBuilder().build()

processResponse(responseCopy, transaction)
collector.onResponseReceived(transaction)

return response
return originalResponse
}

/**
@@ -191,7 +194,7 @@ class ChuckerInterceptor @JvmOverloads constructor(
}
// Let's clone the response Buffer in order to don't cause an IllegalStateException: closed
// if others interceptors are manipulating the body (see #192).
return response.body()?.source()?.buffer()?.clone()
return response.body()?.source()?.buffer()
}

companion object {