So i am building a web application with ktor and using it to make requests to my backend, is some request i want a response header, but ktor is not catching this headers.
In postman and in the dev tools the headers appers
Bellow my ktor client and a request exemple:
private val client = HttpClient(Js)
suspend fun get(accessToken: String, refreshToken: String): Response<User> {
return try {
client.get {
url("${Urls.BACKEND_SERVICE}/user")
header(RequestHeaders.CONTENT_TYPE_HEADER, "application/vnd.kaiqkt_user_v1+json")
header(RequestHeaders.AUTHORIZATION_HEADER, RequestHeaders.BEARER_PREFIX.plus(accessToken))
header(RequestHeaders.REFRESH_TOKEN_HEADER, refreshToken)
}.let { response ->
when (response.status) {
HttpStatusCode.OK -> {
updateLoggedIn(response.headers)
Response(
data = mapper.decodeFromString<User>(response.bodyAsText())
)
}
HttpStatusCode.Unauthorized -> {
Response(
error = Error(
type = ErrorType.UNAUTHORIZED,
message = response.bodyAsText()
)
)
}
else -> Response(
error = Error(
type = ErrorType.UNEXPECTED_ERROR,
message = response.bodyAsText()
)
)
}
}
} catch (ex: Exception) {
throw ex
}
}
Ktor catches the response headers Authorization and Refresh-Token