File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
packages/https/platforms/android/java/com/nativescript/https Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -10,10 +10,22 @@ public class CacheInterceptor {
1010 Request originalRequest = chain .request ();
1111 String cacheControlHeader = originalRequest .header ("Cache-Control" );
1212 Response originalResponse = chain .proceed (originalRequest );
13- if ( cacheControlHeader != null ) {
14- return originalResponse . newBuilder (). header ( "Cache-Control" , cacheControlHeader ). removeHeader ( "Pragma" ). build ();
15- } else {
13+
14+ // Only touch GET responses
15+ if (! "GET" . equalsIgnoreCase ( originalRequest . method ())) {
1616 return originalResponse ;
1717 }
18+
19+ String respCc = originalResponse .header ("Cache-Control" );
20+ // If server didn't provide caching or forbids it, add a safe fallback
21+ if (cacheControlHeader != null && (respCc == null || respCc .isEmpty () || respCc .contains ("no-store" ) || respCc .contains ("no-cache" ))) {
22+ // revalidate on network (max-age=0) but allow stale fallback if error
23+ // stale-if-error may not be honored by everything but OkHttp will cache, enabling our fallback
24+ return originalResponse .newBuilder ()
25+ .removeHeader ("Pragma" )
26+ .header ("Cache-Control" , cacheControlHeader )
27+ .build ();
28+ }
29+ return originalResponse ;
1830 };
1931}
You can’t perform that action at this time.
0 commit comments