-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Servirtium fails to respond with correct headers when using Apollo Kotlin and large response #1065
Comments
Thanks for the investigation. As a very quick way of halving the problem space - have you tried changing to a different Http client implementation and seeing it the problem persists? |
Changing Apollo to use a different client? or changing Servirtium to use a different client? |
Ah, ok, so testing with different http4k clients:
This will definitely unblock me for now. |
So it is something to do with the client. I thought you were using OkHttp and it was failing though? 😕 |
So I wasn't specifying a proxyClient in the servirtium instantiation. I was just depending on whatever the default was. I thought that including the |
yes - we try to use defaults with no dependencies whenever possible :) |
Hm. so the okhttp client works in the mcve i provided, but it does not work in our actual codebase, but now the message is even less clear. Seems like the gzipping is encoding incorrectly somewhere?
|
Actually, I do get it in the mcve. I just had to actually add the direct playback test with some interaction options: object MainInteractionOptions : InteractionOptions {
override fun modify(request: Request): Request {
val newRequest = request
.replaceHeader("Authorization", "00xxx0xxx0xxxxxx")
.replaceHeader("Host", "localhost")
.replaceHeader("User-agent", "agent")
.replaceHeader("Date", "Tue, 28 Jan 2020 14:15:55 GMT")
return super.modify(newRequest)
}
override fun modify(response: Response): Response {
val newResponse = response
.replaceHeader("Content-Encoding", "gzip")
.removeHeaders("X-")
.removeHeader("Set-Cookie")
.replaceHeader("Date", "Tue, 28 Jan 2020 14:15:55 GMT")
return newResponse
}
override fun debugTraffic() = false
}
@Tag("playback-api")
class MainDirectPlaybackTests : MainTest {
override val url by lazy { "http://localhost:${servirtium.port()}" }
private lateinit var servirtium: Http4kServer
@BeforeEach
fun start(info: TestInfo) {
servirtium = ServirtiumServer.Replay(
info.markdownName(),
Disk(File("src/test/resources/servitium-recordings")),
options = MainInteractionOptions
)
servirtium.start()
}
@AfterEach
fun stop() {
servirtium.stop()
}
} |
When trying to record responses when using the Apollo Kotlin client, if the response body is over a certain size then a gzip compression is applied. When this gzip compression is applied, Servirtium (or Apollo Kotlin) fails to set the Content-Encoding header properly when the response makes it back to the Apollo client. This results in the wrong body trying to be unwrapped, and a failure of
This problem could be in Apollo Kotlin or even the underlying OkHttp library, but I spent several hours trying to track down the issue with little gained. I believe the problem 'begins' here in the BridgeInterceptor. This is at least the spot where you can place debug points on these two lines and in the InteractionOptions object and see that the request is sent, the response is received by Servirtium, the headers are set, and then the response sent back. But the response that is sent back has all the headers set to the original values (I think), so it's like the interaction options didn't even happen.
I believe the problem could be due to OkHttp doing something weird with the headers here in the Http1ExchangeCodec, maybe they are copying the headers from the request (that doesn't seem to make sense), but I'm not totally sure.
If I should create an issue with either OkHttp or Apollo Kotlin please let me know, else this mostly seems like a Servirtium error (as it works if you just directly run without the Servirtium proxy).
I've attached an MCVE with 3 test classes that demonstrate the errors:
http4k-servirtium-graphql-mcve.zip
The text was updated successfully, but these errors were encountered: