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 setting request body plain text in transaction #538

Merged
merged 3 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class ChuckerInterceptor private constructor(
val content = io.readFromBuffer(buffer, charset, maxContentLength)
transaction.requestBody = content
} else {
transaction.isResponseBodyPlainText = false
transaction.isRequestBodyPlainText = false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import com.google.gson.stream.JsonReader
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okio.Buffer
import okio.ByteString
import okio.ByteString.Companion.encodeUtf8
import okio.GzipSink
import org.junit.Rule
import org.junit.jupiter.api.assertThrows
Expand Down Expand Up @@ -404,4 +407,19 @@ internal class ChuckerInterceptorTest {
}

private data class Expected(val string: String, val boolean: Boolean, val secondString: String)

@ParameterizedTest
@EnumSource(value = ClientFactory::class)
fun nonPlainTextRequestBody_isRecognizedNotToBePlainText(factory: ClientFactory) {
server.enqueue(MockResponse())
val client = factory.create(chuckerInterceptor)

val request = "\u0080".encodeUtf8().toRequestBody().toServerRequest()
client.newCall(request).execute().body!!.close()

val transaction = chuckerInterceptor.expectTransaction()
assertThat(transaction.isRequestBodyPlainText).isFalse()
}

private fun RequestBody.toServerRequest() = Request.Builder().url(serverUrl).post(this).build()
}