no matter what I do I can never see the header cache-control in the response.
Settings
- retrofit 1.6.0
- okHttp 1.6.0
- okHttp-urlConnection 1.6.0
- gson 2.2.4
- Android 4.0+
1. Configuration
1.1 RestAdapter with my OkHttpClient
OkHttpClient okHttpClient = new OkHttpClient();
Cache cache = new Cache(getCacheDir(), 1024);
okHttpClient.setCache(cache);
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(URL)
.setClient(new OkClient(okHttpClient))
.setLogLevel(LogLevel.HEADERS)
.build();
1.2 RestAdapter with the default OkHttpClient Here, when debugging I could see that the client has cache=null;
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(URL)
.setLogLevel(LogLevel.HEADERS)
.build();
2 Log
For the both configurations the logs are the same.
2.1 REQUEST
06-28 13:24:05.601: D/Retrofit(1581): ---> HTTP GET myUri
06-28 13:24:05.601: D/Retrofit(1581): Cache-Control: public, max-age=640000
06-28 13:24:05.601: D/Retrofit(1581): ---> END HTTP (no body)
2.2 RESPONSE
06-28 13:24:05.701: D/Retrofit(1581): <--- HTTP 200 myUri (102ms)
06-28 13:24:05.701: D/Retrofit(1581): : HTTP/1.1 200 OK
06-28 13:24:05.701: D/Retrofit(1581): Connection: keep-alive
06-28 13:24:05.701: D/Retrofit(1581): Content-Type: text/html
06-28 13:24:05.701: D/Retrofit(1581): Date: Sat, 28 Jun 2014 13:24:01 GMT
06-28 13:24:05.701: D/Retrofit(1581): OkHttp-Received-Millis: 1403961845708
06-28 13:24:05.701: D/Retrofit(1581): OkHttp-Response-Source: NETWORK 200
06-28 13:24:05.701: D/Retrofit(1581): OkHttp-Sent-Millis: 1403961845680
06-28 13:24:05.701: D/Retrofit(1581): Server: nginx/1.6.0
06-28 13:24:05.701: D/Retrofit(1581): Transfer-Encoding: chunked
06-28 13:24:05.701: D/Retrofit(1581): Vary: Accept-Encoding
06-28 13:24:05.701: D/Retrofit(1581): X-Powered-By: PHP/5.5.12-1~dotdeb.1
06-28 13:24:05.701: D/Retrofit(1581): <--- END HTTP (-1-byte body)
EDIT 03/07/2014
I noticed that in this question Retrofit+OkHttp is ok when sending GET requests but gives SocketTimetout when sending POST the asker gets "cache-control" in response.
04-11 18:00:41.291: D/Retrofit(16390): ---> HTTP GET url
04-11 18:00:41.291: D/Retrofit(16390): ---> END HTTP (0-byte body)
04-11 18:00:42.008: D/Retrofit(16390): <--- HTTP 200 url (716ms)
04-11 18:00:42.015: D/Retrofit(16390): : HTTP/1.1 200 OK
04-11 18:00:42.015: D/Retrofit(16390): Cache-Control: max-age=0, private, must-revalidate
Still cannot solve this issue neither in emulators nor in a real device though...