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

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

Open
stefanusayudha opened this issue Mar 6, 2024 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@stefanusayudha
Copy link

stefanusayudha commented Mar 6, 2024

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 stefanusayudha added the bug Something isn't working label Mar 6, 2024
@stefanusayudha stefanusayudha changed the title Ktor Plugin, Body response empty but response received by the app. Ktor Plugin, Pluto didn't show the body content of the request. Mar 6, 2024
@VeceluXa
Copy link

Facing the same issue. Did you find the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants