]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHdrCc.h
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / HttpHdrCc.h
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_HTTPHDRCC_H
10 #define SQUID_HTTPHDRCC_H
11
12 #include "enums.h"
13 #include "MemPool.h"
14 #include "SquidString.h"
15
16 class Packer;
17
18 /** Http Cache-Control header representation
19 *
20 * Store and parse the Cache-Control HTTP header.
21 */
22 class HttpHdrCc
23 {
24
25 public:
26 static const int32_t MAX_AGE_UNKNOWN=-1; //max-age is unset
27 static const int32_t S_MAXAGE_UNKNOWN=-1; //s-maxage is unset
28 static const int32_t MAX_STALE_UNKNOWN=-1; //max-stale is unset
29 ///used to mark a valueless Cache-Control: max-stale directive, which instructs
30 /// us to treat responses of any age as fresh
31 static const int32_t MAX_STALE_ANY=0x7fffffff;
32 static const int32_t STALE_IF_ERROR_UNKNOWN=-1; //stale_if_error is unset
33 static const int32_t MIN_FRESH_UNKNOWN=-1; //min_fresh is unset
34
35 HttpHdrCc() :
36 mask(0), max_age(MAX_AGE_UNKNOWN), s_maxage(S_MAXAGE_UNKNOWN),
37 max_stale(MAX_STALE_UNKNOWN), stale_if_error(STALE_IF_ERROR_UNKNOWN),
38 min_fresh(MIN_FRESH_UNKNOWN) {}
39
40 /// reset data-members to default state
41 void clear();
42
43 /// parse a header-string and fill in appropriate values.
44 bool parse(const String & s);
45
46 //manipulation for Cache-Control: public header
47 bool hasPublic() const {return isSet(CC_PUBLIC);}
48 bool Public() const {return isSet(CC_PUBLIC);}
49 void Public(bool v) {setMask(CC_PUBLIC,v);}
50 void clearPublic() {setMask(CC_PUBLIC,false);}
51
52 //manipulation for Cache-Control: private header
53 bool hasPrivate() const {return isSet(CC_PRIVATE);}
54 const String &Private() const {return private_;}
55 void Private(const String &v) {
56 setMask(CC_PRIVATE,true);
57 if (!v.size())
58 return;
59 // uses append for multi-line headers
60 if (private_.size() > 0)
61 private_.append(",");
62 private_.append(v);
63 }
64 void clearPrivate() {setMask(CC_PRIVATE,false); private_.clean();}
65
66 //manipulation for Cache-Control: no-cache header
67 bool hasNoCache() const {return isSet(CC_NO_CACHE);}
68 const String &noCache() const {return no_cache;}
69 void noCache(const String &v) {
70 setMask(CC_NO_CACHE,true);
71 if (!v.size())
72 return;
73 // uses append for multi-line headers
74 if (no_cache.size() > 0 && v.size() > 0)
75 no_cache.append(",");
76 no_cache.append(v);
77 }
78 void clearNoCache() {setMask(CC_NO_CACHE,false); no_cache.clean();}
79
80 //manipulation for Cache-Control: no-store header
81 bool hasNoStore() const {return isSet(CC_NO_STORE);}
82 bool noStore() const {return isSet(CC_NO_STORE);}
83 void noStore(bool v) {setMask(CC_NO_STORE,v);}
84 void clearNoStore() {setMask(CC_NO_STORE,false);}
85
86 //manipulation for Cache-Control: no-transform header
87 bool hasNoTransform() const {return isSet(CC_NO_TRANSFORM);}
88 bool noTransform() const {return isSet(CC_NO_TRANSFORM);}
89 void noTransform(bool v) {setMask(CC_NO_TRANSFORM,v);}
90 void clearNoTransform() {setMask(CC_NO_TRANSFORM,false);}
91
92 //manipulation for Cache-Control: must-revalidate header
93 bool hasMustRevalidate() const {return isSet(CC_MUST_REVALIDATE);}
94 bool mustRevalidate() const {return isSet(CC_MUST_REVALIDATE);}
95 void mustRevalidate(bool v) {setMask(CC_MUST_REVALIDATE,v);}
96 void clearMustRevalidate() {setMask(CC_MUST_REVALIDATE,false);}
97
98 //manipulation for Cache-Control: proxy-revalidate header
99 bool hasProxyRevalidate() const {return isSet(CC_PROXY_REVALIDATE);}
100 bool proxyRevalidate() const {return isSet(CC_PROXY_REVALIDATE);}
101 void proxyRevalidate(bool v) {setMask(CC_PROXY_REVALIDATE,v);}
102 void clearProxyRevalidate() {setMask(CC_PROXY_REVALIDATE,false);}
103
104 //manipulation for Cache-Control: max-age header
105 bool hasMaxAge() const {return isSet(CC_MAX_AGE);}
106 int32_t maxAge() const { return max_age;}
107 void maxAge(int32_t v) {setValue(max_age,v,CC_MAX_AGE); }
108 void clearMaxAge() {setValue(max_age,MAX_AGE_UNKNOWN,CC_MAX_AGE,false);}
109
110 //manipulation for Cache-Control: s-maxage header
111 bool hasSMaxAge() const {return isSet(CC_S_MAXAGE);}
112 int32_t sMaxAge() const { return s_maxage;}
113 void sMaxAge(int32_t v) {setValue(s_maxage,v,CC_S_MAXAGE); }
114 void clearSMaxAge() {setValue(s_maxage,MAX_AGE_UNKNOWN,CC_S_MAXAGE,false);}
115
116 //manipulation for Cache-Control: max-stale header
117 bool hasMaxStale() const {return isSet(CC_MAX_STALE);}
118 int32_t maxStale() const { return max_stale;}
119 // max-stale has a special value (MAX_STALE_ANY) which correspond to having
120 // the directive without a numeric specification, and directs to consider the object
121 // as always-expired.
122 void maxStale(int32_t v) {setValue(max_stale,v,CC_MAX_STALE);}
123 void clearMaxStale() {setValue(max_stale,MAX_STALE_UNKNOWN,CC_MAX_STALE,false);}
124
125 //manipulation for Cache-Control:min-fresh header
126 bool hasMinFresh() const {return isSet(CC_MIN_FRESH);}
127 int32_t minFresh() const { return min_fresh;}
128 void minFresh(int32_t v) {if (v < 0) return; setValue(min_fresh,v,CC_MIN_FRESH); }
129 void clearMinFresh() {setValue(min_fresh,MIN_FRESH_UNKNOWN,CC_MIN_FRESH,false);}
130
131 //manipulation for Cache-Control: only-if-cached header
132 bool hasOnlyIfCached() const {return isSet(CC_ONLY_IF_CACHED);}
133 bool onlyIfCached() const {return isSet(CC_ONLY_IF_CACHED);}
134 void onlyIfCached(bool v) {setMask(CC_ONLY_IF_CACHED,v);}
135 void clearOnlyIfCached() {setMask(CC_ONLY_IF_CACHED,false);}
136
137 //manipulation for Cache-Control: stale-if-error header
138 bool hasStaleIfError() const {return isSet(CC_STALE_IF_ERROR);}
139 int32_t staleIfError() const { return stale_if_error;}
140 void staleIfError(int32_t v) {setValue(stale_if_error,v,CC_STALE_IF_ERROR); }
141 void clearStaleIfError() {setValue(stale_if_error,STALE_IF_ERROR_UNKNOWN,CC_STALE_IF_ERROR,false);}
142
143 /// check whether the attribute value supplied by id is set
144 _SQUID_INLINE_ bool isSet(http_hdr_cc_type id) const;
145
146 void packInto(Packer * p) const;
147
148 MEMPROXY_CLASS(HttpHdrCc);
149
150 /** bit-mask representing what header values are set among those
151 * recognized by squid.
152 *
153 * managed via EBIT_SET/TEST/CLR
154 */
155 private:
156 int32_t mask;
157 int32_t max_age;
158 int32_t s_maxage;
159 int32_t max_stale;
160 int32_t stale_if_error;
161 int32_t min_fresh;
162 String private_; ///< List of headers sent as value for CC:private="...". May be empty/undefined if the value is missing.
163 String no_cache; ///< List of headers sent as value for CC:no-cache="...". May be empty/undefined if the value is missing.
164
165 /// low-level part of the public set method, performs no checks
166 _SQUID_INLINE_ void setMask(http_hdr_cc_type id, bool newval=true);
167 _SQUID_INLINE_ void setValue(int32_t &value, int32_t new_value, http_hdr_cc_type hdr, bool setting=true);
168
169 public:
170 /**comma-separated representation of the header values which were
171 * received but are not recognized.
172 */
173 String other;
174 };
175
176 MEMPROXY_CLASS_INLINE(HttpHdrCc);
177
178 class StatHist;
179 class StoreEntry;
180
181 void httpHdrCcInitModule(void);
182 void httpHdrCcCleanModule(void);
183 void httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist);
184 void httpHdrCcStatDumper(StoreEntry * sentry, int idx, double val, double size, int count);
185
186 #if _USE_INLINE_
187 #include "HttpHdrCc.cci"
188 #endif
189
190 #endif /* SQUID_HTTPHDRCC_H */