Search in sources :

Example 46 with NetworkResponse

use of com.android.volley.NetworkResponse in project android_frameworks_base by ResurrectionRemix.

the class URLFetcher method getExpirationTimeMillisFromHTTPHeader.

/**
     * Parses the HTTP headers to compute the ttl.
     *
     * @param headers a map that map the header key to the header values. Can be null.
     * @return the ttl in millisecond or null if the ttl is not specified in the header.
     */
private Long getExpirationTimeMillisFromHTTPHeader(Map<String, List<String>> headers) {
    if (headers == null) {
        return null;
    }
    Map<String, String> joinedHeaders = joinHttpHeaders(headers);
    NetworkResponse response = new NetworkResponse(null, joinedHeaders);
    Cache.Entry cachePolicy = HttpHeaderParser.parseCacheHeaders(response);
    if (cachePolicy == null) {
        // Cache is disabled, set the expire time to 0.
        return DO_NOT_CACHE_RESULT;
    } else if (cachePolicy.ttl == 0) {
        // Cache policy is not specified, set the expire time to 0.
        return DO_NOT_CACHE_RESULT;
    } else {
        // cachePolicy.ttl is actually the expire timestamp in millisecond.
        return cachePolicy.ttl;
    }
}
Also used : NetworkResponse(com.android.volley.NetworkResponse) Cache(com.android.volley.Cache)

Aggregations

NetworkResponse (com.android.volley.NetworkResponse)46 Test (org.junit.Test)20 HashMap (java.util.HashMap)17 Cache (com.android.volley.Cache)9 JSONObject (org.json.JSONObject)9 AuthFailureError (com.android.volley.AuthFailureError)8 NetworkError (com.android.volley.NetworkError)8 NoConnectionError (com.android.volley.NoConnectionError)8 ServerError (com.android.volley.ServerError)8 TimeoutError (com.android.volley.TimeoutError)8 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)8 IOException (java.io.IOException)8 MalformedURLException (java.net.MalformedURLException)8 SocketTimeoutException (java.net.SocketTimeoutException)8 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)8 JSONArray (org.json.JSONArray)8 JsonArrayRequest (com.android.volley.toolbox.JsonArrayRequest)7 HttpResponse (org.apache.http.HttpResponse)7 StatusLine (org.apache.http.StatusLine)7 String (java.lang.String)6