Hey, is it expected behaviour that `defaultRequest...
# ktor
m
Hey, is it expected behaviour that
defaultRequest
plugin doesn't override the previous install for
defaultRequest
?
Logging
Plugin does get overwritten as it only prints second Log the second time. Example
Copy code
fun tesss() {
        val client = HttpClient {
            install(Logging) {
                logger = object : Logger {
                    override fun log(message: String) {
                        println("first log#####\n${message}")
                    }
                }
                level = LogLevel.HEADERS
            }
            defaultRequest {
                headers.append(HttpHeaders.Authorization, "Bearer firstAuth")
            }
        }

        runBlocking {
            client.get("<https://www.google.com>")
        }

        val client2 = client.config {
            install(Logging) {
                logger = object : Logger {
                    override fun log(message: String) {
                        println("second log#####\n${message}")
                    }
                }
                level = LogLevel.HEADERS
            }
            defaultRequest {
//                headers.append(HttpHeaders.Authorization, "Bearer secondAuth")
                headers.appendIfNameAbsent(HttpHeaders.Authorization, "Bearer secondAuth")
            }
        }
        runBlocking {
            client2.get("<https://www.google.com>")
        }

    }
Here the second log still prints Bearer firstAuth
This was unexpected behaviour for me
a
Do you mean it's unexpected behavior when there are two
headers.append
calls in both configurations?
m
No what I mean is that, on client1 i have a logger installed and a defaultRequest (that sets a auth), I create client2 based on this config with new logger and new default request that is "installed". It no longer prints the original logger but the original defaultRequest still works and appends the bearer token. I expect it to work like logger and have the newly installed defaultRequest to override the previous installed defaultRequest
a
This is a bug. Can you please file an issue?
m
Sure, its the default request that is wrong right? Not the logger?
a
The problem is only in the DefaultRequest plugin.
👍 1