1 /** @file
2 
3   A brief file description
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 /****************************************************************************
25 
26    HttpTransactCache.h --
27    Created On      : Thu Mar 26 17:19:35 1998
28 
29 
30  ****************************************************************************/
31 #pragma once
32 
33 #include "tscore/ink_platform.h"
34 #include "HttpConfig.h"
35 
36 // This is needed since txn_conf->cache_guaranteed_max_lifetime is currently not
37 // readily available in the cache. ToDo: We should fix this with TS-1919
38 static const time_t CacheHighAgeWatermark = UINT_MAX;
39 struct CacheHTTPInfoVector;
40 
41 enum Variability_t {
42   VARIABILITY_NONE = 0,
43   VARIABILITY_SOME,
44   VARIABILITY_ALL,
45 };
46 
47 class HttpTransactCache
48 {
49 public:
50   /////////////////////////////////
51   // content negotiation support //
52   /////////////////////////////////
53 
54   static int SelectFromAlternates(CacheHTTPInfoVector *cache_vector_data, HTTPHdr *client_request,
55                                   const OverridableHttpConfigParams *cache_lookup_http_config_params);
56 
57   static float calculate_quality_of_match(const OverridableHttpConfigParams *http_config_params, HTTPHdr *client_request,
58                                           HTTPHdr *obj_client_request, HTTPHdr *obj_origin_server_response);
59 
60   static float calculate_quality_of_accept_match(MIMEField *accept_field, MIMEField *content_field);
61 
62   static float calculate_quality_of_accept_charset_match(MIMEField *accept_field, MIMEField *content_field,
63                                                          MIMEField *cached_accept_field = nullptr);
64 
65   static float calculate_quality_of_accept_encoding_match(MIMEField *accept_field, MIMEField *content_field,
66                                                           MIMEField *cached_accept_field = nullptr);
67 
68   // 'encoding_identifier' is a nul-terminated string.
69   static bool match_content_encoding(MIMEField *accept_field, const char *encoding_identifier);
70 
71   static float calculate_quality_of_accept_language_match(MIMEField *accept_field, MIMEField *content_field,
72                                                           MIMEField *cached_accept_field = nullptr);
73 
74   ///////////////////////////////////////////////
75   // variability & server negotiation routines //
76   ///////////////////////////////////////////////
77 
78   static Variability_t CalcVariability(const OverridableHttpConfigParams *http_config_params, HTTPHdr *client_request,
79                                        HTTPHdr *obj_client_request, HTTPHdr *obj_origin_server_response);
80 
81   static HTTPStatus match_response_to_request_conditionals(HTTPHdr *ua_request, HTTPHdr *c_response,
82                                                            ink_time_t response_received_time);
83 };
84