Skip to content

Commit b88c544

Browse files
committed
Fix test
1 parent 9c808dd commit b88c544

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

okhttp/src/main/kotlin/okhttp3/internal/cache/CacheInterceptor.kt

+7-3
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,15 @@ class CacheInterceptor(internal val cache: Cache?) : Interceptor {
290290
}
291291

292292
private fun Request.requestForCache(): Request {
293-
return cacheUrlOverride?.let {
293+
val cacheUrlOverride = cacheUrlOverride
294+
295+
return if (cacheUrlOverride != null && (method == "GET" || method == "POST")) {
294296
newBuilder()
295297
.get()
296-
.url(it)
298+
.url(cacheUrlOverride)
297299
.cacheUrlOverride(null)
298300
.build()
299-
} ?: this
301+
} else {
302+
this
303+
}
300304
}

okhttp/src/test/java/okhttp3/CacheTest.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -1002,9 +1002,20 @@ class CacheTest {
10021002
testRequestMethod("POST", false)
10031003
}
10041004

1005+
@Test
1006+
fun requestMethodPostIsNotCachedUnlessOverriden() {
1007+
// Supported via cacheUrlOverride
1008+
testRequestMethod("POST", true, withOverride = true)
1009+
}
1010+
10051011
@Test
10061012
fun requestMethodPutIsNotCached() {
1007-
testRequestMethod("PUT", false, true)
1013+
testRequestMethod("PUT", false)
1014+
}
1015+
1016+
@Test
1017+
fun requestMethodPutIsNotCachedEvenWithOverride() {
1018+
testRequestMethod("PUT", false, withOverride = true)
10081019
}
10091020

10101021
@Test

0 commit comments

Comments
 (0)