////////////////////////////////////////////////////////////////////////// Name : build_response_from_cache() Description: build a client response from cached response and client request Input : State, warning code to be inserted into the response header Output : Details : This function is called if we decided to serve a client request using a cached response. It is called by h
| 2999 | // |
| 3000 | /////////////////////////////////////////////////////////////////////////////// |
| 3001 | void |
| 3002 | HttpTransact::build_response_from_cache(State *s, HTTPWarningCode warning_code) |
| 3003 | { |
| 3004 | HTTPHdr *client_request = &s->hdr_info.client_request; |
| 3005 | HTTPHdr *cached_response = nullptr; |
| 3006 | HTTPHdr *to_warn = &s->hdr_info.client_response; |
| 3007 | CacheHTTPInfo *obj; |
| 3008 | |
| 3009 | if (s->api_update_cached_object == HttpTransact::UPDATE_CACHED_OBJECT_CONTINUE) { |
| 3010 | obj = &s->cache_info.object_store; |
| 3011 | ink_assert(obj->valid()); |
| 3012 | } else { |
| 3013 | obj = s->cache_info.object_read; |
| 3014 | } |
| 3015 | cached_response = obj->response_get(); |
| 3016 | |
| 3017 | // If the client request is conditional, and the cached copy meets |
| 3018 | // the conditions, do not need to send back the full document, |
| 3019 | // just a NOT_MODIFIED response. |
| 3020 | // If the request is not conditional, |
| 3021 | // the function match_response_to_request_conditionals() returns |
| 3022 | // the code of the cached response, which means that we should send |
| 3023 | // back the full document. |
| 3024 | HTTPStatus client_response_code = |
| 3025 | HttpTransactCache::match_response_to_request_conditionals(client_request, cached_response, s->response_received_time); |
| 3026 | |
| 3027 | switch (client_response_code) { |
| 3028 | case HTTP_STATUS_NOT_MODIFIED: |
| 3029 | // A IMS or INM GET client request with conditions being met |
| 3030 | // by the cached response. Send back a NOT MODIFIED response. |
| 3031 | TxnDbg(dbg_ctl_http_trans, "Not modified"); |
| 3032 | SET_VIA_STRING(VIA_DETAIL_CACHE_LOOKUP, VIA_DETAIL_HIT_CONDITIONAL); |
| 3033 | |
| 3034 | build_response(s, cached_response, &s->hdr_info.client_response, s->client_info.http_version, client_response_code); |
| 3035 | s->cache_info.action = CACHE_DO_NO_ACTION; |
| 3036 | s->next_action = SM_ACTION_INTERNAL_CACHE_NOOP; |
| 3037 | break; |
| 3038 | |
| 3039 | case HTTP_STATUS_PRECONDITION_FAILED: |
| 3040 | // A conditional request with conditions not being met by the cached |
| 3041 | // response. Send back a PRECONDITION FAILED response. |
| 3042 | TxnDbg(dbg_ctl_http_trans, "Precondition Failed"); |
| 3043 | SET_VIA_STRING(VIA_DETAIL_CACHE_LOOKUP, VIA_DETAIL_MISS_CONDITIONAL); |
| 3044 | |
| 3045 | build_response(s, &s->hdr_info.client_response, s->client_info.http_version, client_response_code); |
| 3046 | s->cache_info.action = CACHE_DO_NO_ACTION; |
| 3047 | s->next_action = SM_ACTION_INTERNAL_CACHE_NOOP; |
| 3048 | break; |
| 3049 | |
| 3050 | // Check if cached response supports Range. If it does, append |
| 3051 | // Range transformation plugin |
| 3052 | // A little misnomer. HTTP_STATUS_RANGE_NOT_SATISFIABLE |
| 3053 | // actually means If-Range match fails here. |
| 3054 | // fall through |
| 3055 | default: |
| 3056 | SET_VIA_STRING(VIA_DETAIL_CACHE_LOOKUP, VIA_DETAIL_HIT_SERVED); |
| 3057 | if (s->method == HTTP_WKSIDX_GET || (s->txn_conf->cache_post_method == 1 && s->method == HTTP_WKSIDX_POST) || |
| 3058 | s->api_resp_cacheable == true) { |
nothing calls this directly
no test coverage detected