Challenge - 5 Problems
OkHttp Interceptor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when an OkHttp interceptor modifies the request URL?
Consider an OkHttp interceptor that changes the request URL before proceeding. What will the server receive?
Android Kotlin
val interceptor = Interceptor { chain ->
val newRequest = chain.request().newBuilder()
.url("https://api.example.com/modified")
.build()
chain.proceed(newRequest)
}Attempts:
2 left
💡 Hint
Think about what the interceptor does before calling proceed.
✗ Incorrect
Interceptors can modify the request before sending it. Changing the URL in the interceptor means the server gets the new URL.
❓ lifecycle
intermediate2:00remaining
When is an OkHttp interceptor called during a request?
At what point in the OkHttp request lifecycle does an interceptor run?
Attempts:
2 left
💡 Hint
Interceptors can modify both request and response.
✗ Incorrect
OkHttp interceptors wrap the entire call, so they run before sending the request and after receiving the response.
🔧 Debug
advanced2:00remaining
Why does this interceptor cause a stack overflow error?
Analyze the following interceptor code. Why does it cause a stack overflow?
Android Kotlin
val interceptor = Interceptor { chain ->
val request = chain.request()
chain.proceed(request)
chain.proceed(request)
}Attempts:
2 left
💡 Hint
Check how many times proceed is called.
✗ Incorrect
Calling chain.proceed(request) twice causes the interceptor to recursively call itself repeatedly, causing stack overflow.
🧠 Conceptual
advanced2:00remaining
What is the difference between application and network interceptors in OkHttp?
Choose the correct distinction between application interceptors and network interceptors.
Attempts:
2 left
💡 Hint
Think about when retries and caching happen.
✗ Incorrect
Application interceptors see the entire request/response lifecycle including retries and caching. Network interceptors see data just before it goes on the network.
📝 Syntax
expert2:00remaining
What error does this interceptor code produce?
Examine the Kotlin interceptor code below. What error will it cause?
Android Kotlin
val interceptor = Interceptor { chain ->
val request = chain.request()
val response = chain.proceed(request)
return response
println("Intercepted")
}Attempts:
2 left
💡 Hint
Consider Kotlin lambda expression rules for return statements.
✗ Incorrect
In Kotlin lambdas, 'return' without label tries to return from the enclosing function, which is not allowed here, causing a syntax error.