]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHdrCc.h
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_HTTPHDRCC_H
10 #define SQUID_HTTPHDRCC_H
14 #include "SquidString.h"
18 /** Http Cache-Control header representation
20 * Store and parse the Cache-Control HTTP header.
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
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
) {}
40 /// reset data-members to default state
43 /// parse a header-string and fill in appropriate values.
44 bool parse(const String
& s
);
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);}
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);
59 // uses append for multi-line headers
60 if (private_
.size() > 0)
64 void clearPrivate() {setMask(CC_PRIVATE
,false); private_
.clean();}
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);
73 // uses append for multi-line headers
74 if (no_cache
.size() > 0 && v
.size() > 0)
78 void clearNoCache() {setMask(CC_NO_CACHE
,false); no_cache
.clean();}
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);}
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);}
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);}
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);}
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);}
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);}
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);}
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);}
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);}
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);}
143 /// check whether the attribute value supplied by id is set
144 _SQUID_INLINE_
bool isSet(http_hdr_cc_type id
) const;
146 void packInto(Packer
* p
) const;
148 MEMPROXY_CLASS(HttpHdrCc
);
150 /** bit-mask representing what header values are set among those
151 * recognized by squid.
153 * managed via EBIT_SET/TEST/CLR
160 int32_t stale_if_error
;
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.
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);
170 /**comma-separated representation of the header values which were
171 * received but are not recognized.
176 MEMPROXY_CLASS_INLINE(HttpHdrCc
);
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
);
187 #include "HttpHdrCc.cci"
190 #endif /* SQUID_HTTPHDRCC_H */