////////////////////////////////////////////////////////////////////////// Name : is_request_cache_lookupable() Description: check if a request should be looked up in cache Input : State, request header Output : true or false Details : //////////////////////////////////////////////////////////////////////////
| 6071 | // |
| 6072 | /////////////////////////////////////////////////////////////////////////////// |
| 6073 | bool |
| 6074 | HttpTransact::is_request_cache_lookupable(State *s) |
| 6075 | { |
| 6076 | // ummm, someone has already decided that proxy should tunnel |
| 6077 | if (s->current.mode == TUNNELLING_PROXY) { |
| 6078 | return false; |
| 6079 | } |
| 6080 | // don't bother with remaining checks if we already did a cache lookup |
| 6081 | if (s->cache_info.lookup_count > 0) { |
| 6082 | return true; |
| 6083 | } |
| 6084 | // is cache turned on? |
| 6085 | if (!s->txn_conf->cache_http) { |
| 6086 | SET_VIA_STRING(VIA_DETAIL_TUNNEL, VIA_DETAIL_TUNNEL_CACHE_OFF); |
| 6087 | return false; |
| 6088 | } |
| 6089 | // GET, HEAD, POST, DELETE, and PUT are all cache lookupable |
| 6090 | if (!HttpTransactHeaders::is_method_cache_lookupable(s->method) && s->api_req_cacheable == false) { |
| 6091 | SET_VIA_STRING(VIA_DETAIL_TUNNEL, VIA_DETAIL_TUNNEL_METHOD); |
| 6092 | return false; |
| 6093 | } |
| 6094 | // don't cache page if URL "looks dynamic" and this filter is enabled |
| 6095 | // We can do the check in is_response_cacheable() or here. |
| 6096 | // It may be more efficient if we are not going to cache dynamic looking urls |
| 6097 | // (the default config?) since we don't even need to do cache lookup. |
| 6098 | // So for the time being, it'll be left here. |
| 6099 | |
| 6100 | // If url looks dynamic but a ttl is set, request is cache lookupable |
| 6101 | if ((!s->txn_conf->cache_urls_that_look_dynamic) && url_looks_dynamic(s->hdr_info.client_request.url_get()) && |
| 6102 | (s->cache_control.ttl_in_cache <= 0)) { |
| 6103 | // We do not want to forward the request for a dynamic URL onto the |
| 6104 | // origin server if the value of the Max-Forwards header is zero. |
| 6105 | int max_forwards = -1; |
| 6106 | if (s->hdr_info.client_request.presence(MIME_PRESENCE_MAX_FORWARDS)) { |
| 6107 | MIMEField *max_forwards_f = s->hdr_info.client_request.field_find(MIME_FIELD_MAX_FORWARDS, MIME_LEN_MAX_FORWARDS); |
| 6108 | |
| 6109 | if (max_forwards_f) { |
| 6110 | max_forwards = max_forwards_f->value_get_int(); |
| 6111 | } |
| 6112 | } |
| 6113 | |
| 6114 | if (max_forwards != 0) { |
| 6115 | SET_VIA_STRING(VIA_DETAIL_TUNNEL, VIA_DETAIL_TUNNEL_URL); |
| 6116 | return false; |
| 6117 | } |
| 6118 | } |
| 6119 | |
| 6120 | // Don't look in cache if it's a RANGE request but the cache is not enabled for RANGE. |
| 6121 | if (!s->txn_conf->cache_range_lookup && s->hdr_info.client_request.presence(MIME_PRESENCE_RANGE)) { |
| 6122 | SET_VIA_STRING(VIA_DETAIL_TUNNEL, VIA_DETAIL_TUNNEL_HEADER_FIELD); |
| 6123 | return false; |
| 6124 | } |
| 6125 | |
| 6126 | // Even with "no-cache" directive, we want to do a cache lookup |
| 6127 | // because we need to update our cached copy. |
| 6128 | // Client request "no-cache" directive is handle elsewhere: |
| 6129 | // update_cache_control_information_from_config() |
| 6130 |
nothing calls this directly
no test coverage detected