https://kotlinlang.org logo
#ktor
Title
# ktor
h

Hamza GATTAL

07/11/2022, 3:09 PM
hi, everyone I'm using Ktor client 2.0.x with Bearer Auth. I have many requests don't need authorization. what is the way to tell Ktor don't add authorization header
r

Rustam Siniukov

07/11/2022, 3:27 PM
you can use
sendWithoutRequest
to filter which requests get header by default. like
Copy code
Auth {
  bearer {
    ...
    sendWithoutRequest { it.url.host == "my.host" }
  } 
}
h

Hamza GATTAL

07/11/2022, 5:43 PM
thanks @Rustam Siniukov i get it Auth { bearer { ... sendWithoutRequest { !it.url.pathSegments.containsAll(listOf("", "")) } } }
40 Views