-
Notifications
You must be signed in to change notification settings - Fork 17
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
Support empty buffers on Gzip decompression #139
Merged
pkwarren
merged 10 commits into
connectrpc:main
from
erawhctim:mw/gzip-decompress-EOF-error
Nov 8, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1e1d3a6
Add failing test for GzipCompressionPool.decompress w/empty Buffer
erawhctim e785f9c
reproduce EOFException error with new failing tests in ConnectInterce…
erawhctim 6bca00f
Add okhttp mockwebserver to version catalog
erawhctim 91e733f
Add coroutines test dependency to version catalog
erawhctim acbf39c
Add failing test w/MockWebServer to demonstrate issue 138
erawhctim 4969ccc
fix EOFException on gzip decompress w/empty buffer
erawhctim 09359de
Add license header
erawhctim 5c620eb
Update MockWebServer tests to depend on generated java protos
erawhctim 2c75ee6
Add MockWebServer JUnit4 dependency & use server Rule in mock test
erawhctim ff93b51
spotless apply
erawhctim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
okhttp/src/test/kotlin/com/connectrpc/okhttp/MockWebServerRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2022-2023 The Connect Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.connectrpc.okhttp | ||
|
||
import okhttp3.mockwebserver.MockWebServer | ||
import org.junit.rules.TestWatcher | ||
import org.junit.runner.Description | ||
|
||
class MockWebServerRule( | ||
private val port: Int = 0, | ||
) : TestWatcher() { | ||
|
||
lateinit var server: MockWebServer | ||
private set | ||
|
||
override fun starting(description: Description) { | ||
super.starting(description) | ||
server = MockWebServer() | ||
server.start(port) | ||
} | ||
|
||
override fun finished(description: Description) { | ||
super.finished(description) | ||
server.shutdown() | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
okhttp/src/test/kotlin/com/connectrpc/okhttp/MockWebServerTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2022-2023 The Connect Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.connectrpc.okhttp | ||
|
||
import com.connectrpc.Code | ||
import com.connectrpc.ProtocolClientConfig | ||
import com.connectrpc.RequestCompression | ||
import com.connectrpc.compression.GzipCompressionPool | ||
import com.connectrpc.eliza.v1.ElizaServiceClient | ||
import com.connectrpc.eliza.v1.sayRequest | ||
import com.connectrpc.extensions.GoogleJavaProtobufStrategy | ||
import com.connectrpc.impl.ProtocolClient | ||
import com.connectrpc.protocols.NetworkProtocol | ||
import kotlinx.coroutines.test.runTest | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Protocol | ||
import okhttp3.mockwebserver.MockResponse | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class MockWebServerTests { | ||
|
||
@get:Rule val mockWebServerRule = MockWebServerRule() | ||
|
||
@Test | ||
fun `compressed empty failure response is parsed correctly`() = runTest { | ||
mockWebServerRule.server.enqueue( | ||
MockResponse().apply { | ||
addHeader("accept-encoding", "gzip") | ||
addHeader("content-encoding", "gzip") | ||
setBody("{}") | ||
setResponseCode(401) | ||
}, | ||
) | ||
|
||
val host = mockWebServerRule.server.url("/") | ||
|
||
val protocolClient = ProtocolClient( | ||
ConnectOkHttpClient( | ||
OkHttpClient.Builder() | ||
.protocols(listOf(Protocol.HTTP_2, Protocol.HTTP_1_1)) | ||
.build(), | ||
), | ||
ProtocolClientConfig( | ||
host = host.toString(), | ||
serializationStrategy = GoogleJavaProtobufStrategy(), | ||
networkProtocol = NetworkProtocol.CONNECT, | ||
requestCompression = RequestCompression(0, GzipCompressionPool), | ||
compressionPools = listOf(GzipCompressionPool), | ||
), | ||
) | ||
|
||
val response = ElizaServiceClient(protocolClient).say(sayRequest { sentence = "hello" }) | ||
|
||
mockWebServerRule.server.takeRequest().apply { | ||
assertThat(path).isEqualTo("/connectrpc.eliza.v1.ElizaService/Say") | ||
} | ||
|
||
assertThat(response.code).isEqualTo(Code.UNKNOWN) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrote a small connect-go example and verified that it gets the same result here. Thanks for adding these tests - they'll make it much easier to test different edge conditions outside of the conformance tests in the future. |
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense and is a good change (and we've amended the spec to account for it):
I think in this specific error case though, there was another issue. In
connect-kotlin/library/src/main/kotlin/com/connectrpc/protocols/ConnectInterceptor.kt
Lines 98 to 104 in 37fb4f9
parseConnectUnaryException
, and then on line 104 we're again trying to consume the same message body a second time. If the code is not OK, we shouldn't be attempting to consume a response message and instead should just set message to an empty buffer.