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

Anudeep Ananth

10/26/2023, 6:52 PM
I just migrated from Java 8 runtime to Java 17 on my Ktor project that runs on Google App Engine Standard environment. The project compiles and is being deployed without issues, the request response is sent by the server, Even querying a database(MongoDB atlas in this case) also works. The issue I see is when there is a header attached to the request, the Ktor route fails to read them and throws a with Http 500 error. Here is my client(Android - Retrofit ) code:
Copy code
val request = chain.request()
    val authTokenRequest = request.newBuilder()
        .header(FIRE_AUTH_UID_KEY, mFirebaseAuth.currentUser?.uid?:"fakeUid")
        .header(FIRE_AUTH_TOKEN_KEY, returnUserFireAuthIdToken())
        .addHeader(FIRE_APP_CHECK_TOKEN_KEY, returnUserFireBaseAppCheck())
        .build()

object RetrofitInterceptorObject {

    val retrofitInterceptorObject by lazy {
        RetrofitInterceptor()
    }

}

private val client = OkHttpClient.Builder()
    .addInterceptor(RetrofitInterceptorObject.retrofitInterceptorObject)
    .build()
Here is the get request
Copy code
@GET("/getInviteCodeToShare")
suspend fun getInviteCodeToShare(): Response<InviteCodeToShare>
Ktor route:
Copy code
fun Route.getInviteCodeToShare() {

route("/getInviteCodeToShare") {
    get {
        val uid = call.request.header(FIRE_AUTH_UID_KEY)!! //this is what is causing the error
        val authToken = call.request.header(FIRE_AUTH_TOKEN_KEY)!!
        val userAuthDetails = UserAuthDetails(uid, authToken)

        if ( isUserValid(userAuthDetails) ) {
            //Successful
            call.respond(HttpStatusCode.OK, getTheInviteCodeToShare(uid))
            } else {
                //else return you are not logged in to client
                call.respond(HttpStatusCode.Unauthorized, unAuthorizedRequest)
                println("User is not authorized")
            }
        }
    }
}
This code was working without issues in Java 8 runtime.
e

e5l

10/27/2023, 1:12 PM
Hey @Anudeep Ananth, thanks for the catch! It looks like a bug to me. Could you log an issue with the sample? We will take a look
a

Anudeep Ananth

10/27/2023, 5:02 PM
Hey @e5l Alrite sure…
I’ve logged the issue : Request headers not being retrieved in Java 11 runtime : KTOR-6413 (jetbrains.com) Really hope this gets fixed, AWS and Google Cloud are ending support for Java 8 runtime in a couple of months.
🙏 1
2 Views