WangDaYeeeeee / GeometricWeather

A Material Design Weather Application
GNU Lesser General Public License v3.0
2.44k stars 186 forks source link

[ToS] Comply with the Expires header #244

Closed papjul closed 1 year ago

papjul commented 3 years ago

Hi,

Many weather providers request that developers should/must comply with the Expires HTTP header.

The Expires header contains the date/time after which data will be updated on server side. Until then, it is useless (and harmful for the bandwidth) to refresh.

As per AccuWeather guidelines:

Refresh information from the AccuWeather API for your device based upon the cache expires time in the response headers

Example:
   Response Headers
    Cache-Control: public
    Content-Encoding: gzip
    Content-Type: application/json; charset=utf-8
    Date: Wed, 29 Aug 2012 14:55:33 GMT
    Expires: Thu, 30 Aug 2012 14:56:34 GMT
    Server: Microsoft-IIS/7.5
    Server: Microsoft-IIS/7.0
    Transfer-Encoding: chunked
    Vary: Accept-Encoding
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET

In this example, do not refresh until: Thu, 30 Aug 2012 14:56:34 GMT

This is also a prerequisite for #242

Would it be possible to make sure data is not refreshed until that date? This would apply to:

This would also save up some precious API calls from useless refreshes, as seen in #223.

rthery commented 2 years ago

Hum, good http client library usually handles that for you. The request will be cached until the Expires value, and any identical requests issued will just return the cached response immediately.

I'm not familiar with Android API, but this looks like this could do the job ? (2min googlefu, may be wrong :D) https://developer.android.com/reference/android/net/http/HttpResponseCache

papjul commented 2 years ago

We use the Retrofit dependency to ease API handling. According to my HTTP interceptor, it makes a new request everytime.

rthery commented 2 years ago

I see, OkHttpClient (which is used by Retrofit) supports caching, and from what I can see here the cache is not enabled: https://github.com/WangDaYeeeeee/GeometricWeather/blob/master/app/src/main/java/wangdaye/com/geometricweather/common/retrofit/TLSCompactHelper.java#L90

I can do some tests locally and issue a PR

papjul commented 1 year ago

Fixed in #440