////////////////////////////////////////////////////////////////////////// Name : is_response_cacheable() Description: check if a response is cacheable Input : State, request header, response header Output : true or false Details : //////////////////////////////////////////////////////////////////////////
| 6176 | // |
| 6177 | /////////////////////////////////////////////////////////////////////////////// |
| 6178 | bool |
| 6179 | HttpTransact::is_response_cacheable(State *s, HTTPHdr *request, HTTPHdr *response) |
| 6180 | { |
| 6181 | // If the use_client_target_addr is specified but the client |
| 6182 | // specified OS addr does not match any of trafficserver's looked up |
| 6183 | // host addresses, do not allow cache. This may cause DNS cache poisoning |
| 6184 | // of other trafficserver clients. The flag is set in the |
| 6185 | // process_host_db_info method |
| 6186 | if (!s->dns_info.cta_validated_p && s->client_info.is_transparent) { |
| 6187 | TxnDbg(dbg_ctl_http_trans, "Lookup not validated. Possible DNS cache poison. Don't cache"); |
| 6188 | return false; |
| 6189 | } |
| 6190 | |
| 6191 | // the plugin may decide we don't want to cache the response |
| 6192 | if (s->api_server_response_no_store) { |
| 6193 | return false; |
| 6194 | } |
| 6195 | // if method is not GET or HEAD, do not cache. |
| 6196 | // Note: POST is also cacheable with Expires or Cache-control. |
| 6197 | // but due to INKqa11567, we are not caching POST responses. |
| 6198 | // Basically, the problem is the resp for POST url1 req should not |
| 6199 | // be served to a GET url1 request, but we just match URL not method. |
| 6200 | int req_method = request->method_get_wksidx(); |
| 6201 | if (!(HttpTransactHeaders::is_method_cacheable(s->txn_conf, req_method)) && s->api_req_cacheable == false) { |
| 6202 | TxnDbg(dbg_ctl_http_trans, "only GET, and some HEAD and POST are cacheable"); |
| 6203 | return false; |
| 6204 | } |
| 6205 | // TxnDbg(dbg_ctl_http_trans, "[is_response_cacheable] method is cacheable"); |
| 6206 | // If the request was not looked up in the cache, the response |
| 6207 | // should not be cached (same subsequent requests will not be |
| 6208 | // looked up, either, so why cache this). |
| 6209 | if (!(is_request_cache_lookupable(s))) { |
| 6210 | TxnDbg(dbg_ctl_http_trans, "request is not cache lookupable, response is not cacheable"); |
| 6211 | return false; |
| 6212 | } |
| 6213 | // already has a fresh copy in the cache |
| 6214 | if (s->range_setup == RANGE_NOT_HANDLED) { |
| 6215 | return false; |
| 6216 | } |
| 6217 | |
| 6218 | // Check whether the response is cacheable based on its cookie |
| 6219 | // If there are cookies in response but a ttl is set, allow caching |
| 6220 | if ((s->cache_control.ttl_in_cache <= 0) && |
| 6221 | do_cookies_prevent_caching(static_cast<int>(s->txn_conf->cache_responses_to_cookies), request, response)) { |
| 6222 | TxnDbg(dbg_ctl_http_trans, "response has uncachable cookies, response is not cacheable"); |
| 6223 | return false; |
| 6224 | } |
| 6225 | // if server spits back a WWW-Authenticate |
| 6226 | if ((s->txn_conf->cache_ignore_auth) == 0 && response->presence(MIME_PRESENCE_WWW_AUTHENTICATE)) { |
| 6227 | TxnDbg(dbg_ctl_http_trans, "response has WWW-Authenticate, response is not cacheable"); |
| 6228 | return false; |
| 6229 | } |
| 6230 | // does server explicitly forbid storing? |
| 6231 | // If OS forbids storing but a ttl is set, allow caching |
| 6232 | if (!s->cache_info.directives.does_server_permit_storing && (s->cache_control.ttl_in_cache <= 0)) { |
| 6233 | TxnDbg(dbg_ctl_http_trans, "server does not permit storing and config file does not " |
| 6234 | "indicate that server directive should be ignored"); |
| 6235 | return false; |
nothing calls this directly
no test coverage detected