pluto icon indicating copy to clipboard operation
pluto copied to clipboard

Ktor Plugin, Pluto didn't show the body content of the request.

Open stefanusayudha opened this issue 1 year ago • 0 comments

Describe the bug Response OK 200. Response is received by the ktor and successfully displayed to the app but Pluto didn't show the response body.

To Reproduce Steps to reproduce the behavior:

  1. install pluto plugin to ktor HtppClient
class MainApplication: Application() {

    override fun attachBaseContext(base: Context?) {
        base?.run(MainContext::init)
        super.attachBaseContext(base)
    }

    override fun getBaseContext(): Context {
        return MainContext.get().context
    }

    override fun onCreate() {
        super.onCreate()
        applyPlutoExtension()
    }

}

fun Application.applyPlutoExtension() {
    Pluto.Installer(this)
        .addPlugin(PlutoNetworkPlugin())
        .addPlugin(PlutoLoggerPlugin())
        .addPlugin(PlutoSharePreferencesPlugin())
        .addPlugin(PlutoExceptionsPlugin())
        .addPlugin(PlutoRoomsDatabasePlugin())
        .addPlugin(PlutoDatastorePreferencesPlugin())
        .install()

    also {
        if (BuildConfig.DEBUG)
            (MainContext.get() as WebRepositoryContext)
                .interceptBuilder {
                    install(PlutoKtorInterceptor)
                }
    }
}

class WebRepositoryContextDelegate(
    val context: Context,
) : WebRepositoryContext {

    private val builders = mutableListOf<HttpClientConfig<*>.() -> Unit>()

    override val httpClient: HttpClient by lazy {
        createHttpClient(
            builders = builders
        )
    }

    override fun interceptBuilder(
        httpClientBuilder: HttpClientConfig<*>.() -> Unit
    ) {
        builders.add(httpClientBuilder)
    }
}

fun createHttpClient(
    builders: List<HttpClientConfig<*>.() -> Unit> = listOf()
) = HttpClient {
    builders.forEach {
        it.invoke(this)
    }
}
  1. make network request.
  2. for successful request, body response is empty like in the picture i attached.

Expected behavior Show response data in response body.

Screenshots Screenshot 2024-03-06 at 11 28 10

Smartphone (please complete the following information):

  • Device: Android Emulator
  • OS: Upside Down Cake Privacy Sandbox Preview (from android studio)
  • Client: Ktor HttpClient
  • 2.2.1 (latest)

Additional context

stefanusayudha avatar Mar 06 '24 04:03 stefanusayudha