Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
buildbreaker committed May 10, 2023
1 parent 50e5a2f commit 29c6425
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ProtocolClientConfig(
val requestCompression: RequestCompression? = null,
val enableGet: Boolean = false,
val getMaxUrlBytes: Int = 50_000,
val getFallback: Boolean = false,
val getFallback: Boolean = true,
// Set of interceptors that should be invoked with requests/responses.
interceptors: List<(ProtocolClientConfig) -> Interceptor> = emptyList(),
// Compression pools that provide support for the provided `compressionName`, as well as any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ internal class ConnectInterceptor(
}
val serializationStrategy = clientConfig.serializationStrategy
val requestCodec = serializationStrategy.codec(request.methodSpec.requestClass)
val isCacheableGetMethod = clientConfig.enableGet &&
request.methodSpec.idempotency == Idempotency.NO_SIDE_EFFECTS
if (isCacheableGetMethod) {
if (shouldUseGetMethod(request, finalRequestBody)) {
val url = getUrlFromMethodSpec(
request,
requestCodec,
Expand Down Expand Up @@ -129,6 +127,17 @@ internal class ConnectInterceptor(
)
}

private fun shouldUseGetMethod(request: HTTPRequest, finalRequestBody: Buffer): Boolean {
if (request.methodSpec.idempotency == Idempotency.NO_SIDE_EFFECTS &&
clientConfig.enableGet) {
if (clientConfig.getFallback) {
return clientConfig.getMaxUrlBytes < finalRequestBody.size
}
return true
}
return false
}

override fun streamFunction(): StreamFunction {
val requestCompression = clientConfig.requestCompression
return StreamFunction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,30 @@ class ConnectInterceptorTest {
val completion = result as StreamResult.Complete
assertThat(completion.code).isEqualTo(Code.UNKNOWN)
}

@Test
fun getRequestTest() {
/**
* The matrix is the following:
* get enabled: true
* get fallback: true
* max bytes over limit: true
* E: URL is correctly constructed for a GET
*
* get enabled: true
* get fallback: true
* max bytes over limit: false
* E: POST request is made
*
* get enabled: true
* get fallback: false
* max bytes over limit: n/a since we always shove it in the url
* E: URL is correctly constructed with the max bytes = 0
*
* get enabled: false
* get fallback: n/a since we always use the POST path
* max bytes over limit: n/a since this is not read
* E: POST request is made
*/
}
}

0 comments on commit 29c6425

Please sign in to comment.