File tree 2 files changed +19
-4
lines changed
main/kotlin/okhttp3/internal/cache
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -290,11 +290,15 @@ class CacheInterceptor(internal val cache: Cache?) : Interceptor {
290
290
}
291
291
292
292
private fun Request.requestForCache (): Request {
293
- return cacheUrlOverride?.let {
293
+ val cacheUrlOverride = cacheUrlOverride
294
+
295
+ return if (cacheUrlOverride != null && (method == " GET" || method == " POST" )) {
294
296
newBuilder()
295
297
.get()
296
- .url(it )
298
+ .url(cacheUrlOverride )
297
299
.cacheUrlOverride(null )
298
300
.build()
299
- } ? : this
301
+ } else {
302
+ this
303
+ }
300
304
}
Original file line number Diff line number Diff line change @@ -1002,9 +1002,20 @@ class CacheTest {
1002
1002
testRequestMethod(" POST" , false )
1003
1003
}
1004
1004
1005
+ @Test
1006
+ fun requestMethodPostIsNotCachedUnlessOverriden () {
1007
+ // Supported via cacheUrlOverride
1008
+ testRequestMethod(" POST" , true , withOverride = true )
1009
+ }
1010
+
1005
1011
@Test
1006
1012
fun requestMethodPutIsNotCached () {
1007
- testRequestMethod(" PUT" , false , true )
1013
+ testRequestMethod(" PUT" , false )
1014
+ }
1015
+
1016
+ @Test
1017
+ fun requestMethodPutIsNotCachedEvenWithOverride () {
1018
+ testRequestMethod(" PUT" , false , withOverride = true )
1008
1019
}
1009
1020
1010
1021
@Test
You can’t perform that action at this time.
0 commit comments