From 4e89fccc105667259756ae6f1ea95c0642349ed3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakob=20M=C3=B6ller?= <jakob.moeller@sap.com>
Date: Thu, 11 Jun 2020 10:01:22 +0200
Subject: [PATCH] Remove Offline Cache Interceptor (#368)

Signed-off-by: d067928 <jakob.moeller@sap.com>
---
 .../rki/coronawarnapp/http/ServiceFactory.kt  |  4 --
 .../interceptor/OfflineCacheInterceptor.kt    | 49 -------------------
 2 files changed, 53 deletions(-)
 delete mode 100644 Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/interceptor/OfflineCacheInterceptor.kt

diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/ServiceFactory.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/ServiceFactory.kt
index b1b9cc6f8..ae9366bfd 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/ServiceFactory.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/ServiceFactory.kt
@@ -5,7 +5,6 @@ import de.rki.coronawarnapp.BuildConfig
 import de.rki.coronawarnapp.CoronaWarnApplication
 import de.rki.coronawarnapp.exception.http.ServiceFactoryException
 import de.rki.coronawarnapp.http.config.HTTPVariables
-import de.rki.coronawarnapp.http.interceptor.OfflineCacheInterceptor
 import de.rki.coronawarnapp.http.interceptor.RetryInterceptor
 import de.rki.coronawarnapp.http.interceptor.WebSecurityVerificationInterceptor
 import de.rki.coronawarnapp.http.service.DistributionService
@@ -47,9 +46,6 @@ class ServiceFactory {
         HttpLoggingInterceptor().also {
             if (BuildConfig.DEBUG) it.setLevel(HttpLoggingInterceptor.Level.BODY)
         },
-        OfflineCacheInterceptor(
-            CoronaWarnApplication.getAppContext()
-        ),
         RetryInterceptor(),
         HttpErrorParser()
     )
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/interceptor/OfflineCacheInterceptor.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/interceptor/OfflineCacheInterceptor.kt
deleted file mode 100644
index 929e46f7e..000000000
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/interceptor/OfflineCacheInterceptor.kt
+++ /dev/null
@@ -1,49 +0,0 @@
-package de.rki.coronawarnapp.http.interceptor
-
-import android.content.Context
-import de.rki.coronawarnapp.util.ConnectivityHelper.isNetworkEnabled
-import okhttp3.Interceptor
-import okhttp3.Response
-
-class OfflineCacheInterceptor(private val context: Context) : Interceptor {
-    companion object {
-        private const val MAX_AGE = 5
-        private const val MAX_STALE_DAYS = 1
-        private const val MAX_STALE = 60 * 60 * 24 * MAX_STALE_DAYS
-    }
-
-    override fun intercept(chain: Interceptor.Chain): Response {
-        // Get the request from the chain.
-        var request = chain.request()
-        /*
-        *  Leveraging the advantage of using Kotlin,
-        *  we initialize the request and change its header depending on whether
-        *  the device is connected to Internet or not.
-        */
-        request = if (isNetworkEnabled(context)) {
-            /*
-             *  If there is Internet, get the cache that was stored 5 seconds ago.
-             *  If the cache is older than 5 seconds, then discard it,
-             *  and indicate an error in fetching the response.
-             *  The 'max-age' attribute is responsible for this behavior.
-             */
-            request.newBuilder().header(
-                "Cache-Control",
-                "public, max-age=$MAX_AGE"
-            ).build()
-        } else {
-            /*
-            *  If there is no Internet, get the cache that was stored 1 days ago.
-            *  If the cache is older than 1 day, then discard it,
-            *  and indicate an error in fetching the response.
-            *  The 'max-stale' attribute is responsible for this behavior.
-            *  The 'only-if-cached' attribute indicates to not retrieve new data; fetch the cache only instead.
-            */
-            request.newBuilder().header(
-                "Cache-Control",
-                "public, only-if-cached, max-stale=$MAX_STALE"
-            ).build()
-        }
-        return chain.proceed(request)
-    }
-}
-- 
GitLab