Skip to content

Commit

Permalink
Fix setting request body plain text in transaction (#538)
Browse files Browse the repository at this point in the history
* Fix setting request body plain text in transaction

* Add test for plain text request body
  • Loading branch information
MiSikora authored Jan 29, 2021
1 parent d42f9d8 commit ac2db2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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()
}

0 comments on commit ac2db2f

Please sign in to comment.