android - httpUrlConnection not returning cached response when server returns HTTP_NOT_MODIFIED -
i have api request returns response , response headers last-modified , date. using httpurlconnection making http.get requests. using httpresponsecache cache responses.
when server returns response code 200 ,the response cached. i'm facing 2 issues now.
first : when second time api requested, httpurlconnection sets 'date' header's value 'if-modified-since' header instead of using 'last-modified' header's value.
i solved issue manually setting if-modified-since header cached response. server returns 304 second time api requested.
here comes second issue.
second : if server returns 304 , response cached ,then httpurlconnection returns cached response , response code 200. works desired in case of api response has etag header in response. responses last-modified header , httpurlconnection returns response code 304 , not return cached response.has 1 encountered similar issue ?
please find below java implementation api request.
url url = new url(this.url); httpurlconnection conn = getprotocoltype(url); conn.setrequestmethod("get"); conn.setreadtimeout(timeout); conn.setconnecttimeout(timeout); conn.setinstancefollowredirects(true); conn.setrequestproperty("user-agent", this.useragent); conn.setrequestproperty("cache-control", "max-age=0"); conn.setusecaches(true); conn.setdefaultusecaches(true); conn.connect(); this.responsecode = conn.getresponsecode();
Comments
Post a Comment