]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHdrCc.h
2 * Copyright (C) 1996-2017 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
13 #include "mem/forward.h"
14 #include "SquidString.h"
19 enum HttpHdrCcType
: unsigned char {
33 CC_IMMUTABLE
, /* draft-mcmanus-immutable-00 */
35 CC_ENUM_END
/* also used to mean "invalid" */
38 /** Http Cache-Control header representation
40 * Store and parse the Cache-Control HTTP header.
44 MEMPROXY_CLASS(HttpHdrCc
);
47 static const int32_t MAX_AGE_UNKNOWN
=-1; //max-age is unset
48 static const int32_t S_MAXAGE_UNKNOWN
=-1; //s-maxage is unset
49 static const int32_t MAX_STALE_UNKNOWN
=-1; //max-stale is unset
50 ///used to mark a valueless Cache-Control: max-stale directive, which instructs
51 /// us to treat responses of any age as fresh
52 static const int32_t MAX_STALE_ANY
=0x7fffffff;
53 static const int32_t STALE_IF_ERROR_UNKNOWN
=-1; //stale_if_error is unset
54 static const int32_t MIN_FRESH_UNKNOWN
=-1; //min_fresh is unset
57 mask(0), max_age(MAX_AGE_UNKNOWN
), s_maxage(S_MAXAGE_UNKNOWN
),
58 max_stale(MAX_STALE_UNKNOWN
), stale_if_error(STALE_IF_ERROR_UNKNOWN
),
59 min_fresh(MIN_FRESH_UNKNOWN
) {}
61 /// reset data-members to default state
64 /// parse a header-string and fill in appropriate values.
65 bool parse(const String
& s
);
67 //manipulation for Cache-Control: public header
68 bool hasPublic() const {return isSet(HttpHdrCcType::CC_PUBLIC
);}
69 bool Public() const {return isSet(HttpHdrCcType::CC_PUBLIC
);}
70 void Public(bool v
) {setMask(HttpHdrCcType::CC_PUBLIC
,v
);}
71 void clearPublic() {setMask(HttpHdrCcType::CC_PUBLIC
,false);}
73 //manipulation for Cache-Control: private header
74 bool hasPrivate() const {return isSet(HttpHdrCcType::CC_PRIVATE
);}
75 const String
&Private() const {return private_
;}
76 void Private(const String
&v
) {
77 setMask(HttpHdrCcType::CC_PRIVATE
,true);
80 // uses append for multi-line headers
81 if (private_
.size() > 0)
85 void clearPrivate() {setMask(HttpHdrCcType::CC_PRIVATE
,false); private_
.clean();}
87 //manipulation for Cache-Control: no-cache header
88 bool hasNoCache() const {return isSet(HttpHdrCcType::CC_NO_CACHE
);}
89 const String
&noCache() const {return no_cache
;}
90 void noCache(const String
&v
) {
91 setMask(HttpHdrCcType::CC_NO_CACHE
,true);
94 // uses append for multi-line headers
95 if (no_cache
.size() > 0 && v
.size() > 0)
99 void clearNoCache() {setMask(HttpHdrCcType::CC_NO_CACHE
,false); no_cache
.clean();}
101 //manipulation for Cache-Control: no-store header
102 bool hasNoStore() const {return isSet(HttpHdrCcType::CC_NO_STORE
);}
103 bool noStore() const {return isSet(HttpHdrCcType::CC_NO_STORE
);}
104 void noStore(bool v
) {setMask(HttpHdrCcType::CC_NO_STORE
,v
);}
105 void clearNoStore() {setMask(HttpHdrCcType::CC_NO_STORE
,false);}
107 //manipulation for Cache-Control: no-transform header
108 bool hasNoTransform() const {return isSet(HttpHdrCcType::CC_NO_TRANSFORM
);}
109 bool noTransform() const {return isSet(HttpHdrCcType::CC_NO_TRANSFORM
);}
110 void noTransform(bool v
) {setMask(HttpHdrCcType::CC_NO_TRANSFORM
,v
);}
111 void clearNoTransform() {setMask(HttpHdrCcType::CC_NO_TRANSFORM
,false);}
113 //manipulation for Cache-Control: must-revalidate header
114 bool hasMustRevalidate() const {return isSet(HttpHdrCcType::CC_MUST_REVALIDATE
);}
115 bool mustRevalidate() const {return isSet(HttpHdrCcType::CC_MUST_REVALIDATE
);}
116 void mustRevalidate(bool v
) {setMask(HttpHdrCcType::CC_MUST_REVALIDATE
,v
);}
117 void clearMustRevalidate() {setMask(HttpHdrCcType::CC_MUST_REVALIDATE
,false);}
119 //manipulation for Cache-Control: proxy-revalidate header
120 bool hasProxyRevalidate() const {return isSet(HttpHdrCcType::CC_PROXY_REVALIDATE
);}
121 bool proxyRevalidate() const {return isSet(HttpHdrCcType::CC_PROXY_REVALIDATE
);}
122 void proxyRevalidate(bool v
) {setMask(HttpHdrCcType::CC_PROXY_REVALIDATE
,v
);}
123 void clearProxyRevalidate() {setMask(HttpHdrCcType::CC_PROXY_REVALIDATE
,false);}
125 //manipulation for Cache-Control: max-age header
126 bool hasMaxAge() const {return isSet(HttpHdrCcType::CC_MAX_AGE
);}
127 int32_t maxAge() const { return max_age
;}
128 void maxAge(int32_t v
) {setValue(max_age
,v
,HttpHdrCcType::CC_MAX_AGE
); }
129 void clearMaxAge() {setValue(max_age
,MAX_AGE_UNKNOWN
,HttpHdrCcType::CC_MAX_AGE
,false);}
131 //manipulation for Cache-Control: s-maxage header
132 bool hasSMaxAge() const {return isSet(HttpHdrCcType::CC_S_MAXAGE
);}
133 int32_t sMaxAge() const { return s_maxage
;}
134 void sMaxAge(int32_t v
) {setValue(s_maxage
,v
,HttpHdrCcType::CC_S_MAXAGE
); }
135 void clearSMaxAge() {setValue(s_maxage
,MAX_AGE_UNKNOWN
,HttpHdrCcType::CC_S_MAXAGE
,false);}
137 //manipulation for Cache-Control: max-stale header
138 bool hasMaxStale() const {return isSet(HttpHdrCcType::CC_MAX_STALE
);}
139 int32_t maxStale() const { return max_stale
;}
140 // max-stale has a special value (MAX_STALE_ANY) which correspond to having
141 // the directive without a numeric specification, and directs to consider the object
142 // as always-expired.
143 void maxStale(int32_t v
) {setValue(max_stale
,v
,HttpHdrCcType::CC_MAX_STALE
);}
144 void clearMaxStale() {setValue(max_stale
,MAX_STALE_UNKNOWN
,HttpHdrCcType::CC_MAX_STALE
,false);}
146 //manipulation for Cache-Control:min-fresh header
147 bool hasMinFresh() const {return isSet(HttpHdrCcType::CC_MIN_FRESH
);}
148 int32_t minFresh() const { return min_fresh
;}
149 void minFresh(int32_t v
) {if (v
< 0) return; setValue(min_fresh
,v
,HttpHdrCcType::CC_MIN_FRESH
); }
150 void clearMinFresh() {setValue(min_fresh
,MIN_FRESH_UNKNOWN
,HttpHdrCcType::CC_MIN_FRESH
,false);}
152 //manipulation for Cache-Control: only-if-cached header
153 bool hasOnlyIfCached() const {return isSet(HttpHdrCcType::CC_ONLY_IF_CACHED
);}
154 bool onlyIfCached() const {return isSet(HttpHdrCcType::CC_ONLY_IF_CACHED
);}
155 void onlyIfCached(bool v
) {setMask(HttpHdrCcType::CC_ONLY_IF_CACHED
,v
);}
156 void clearOnlyIfCached() {setMask(HttpHdrCcType::CC_ONLY_IF_CACHED
,false);}
158 //manipulation for Cache-Control: stale-if-error header
159 bool hasStaleIfError() const {return isSet(HttpHdrCcType::CC_STALE_IF_ERROR
);}
160 int32_t staleIfError() const { return stale_if_error
;}
161 void staleIfError(int32_t v
) {setValue(stale_if_error
,v
,HttpHdrCcType::CC_STALE_IF_ERROR
); }
162 void clearStaleIfError() {setValue(stale_if_error
,STALE_IF_ERROR_UNKNOWN
,HttpHdrCcType::CC_STALE_IF_ERROR
,false);}
164 //manipulation for Cache-Control: immutable header
165 bool Immutable() const {return isSet(HttpHdrCcType::CC_IMMUTABLE
);}
166 void Immutable(bool v
) {setMask(HttpHdrCcType::CC_IMMUTABLE
,v
);}
167 void clearImmutable() {setMask(HttpHdrCcType::CC_IMMUTABLE
,false);}
169 /// check whether the attribute value supplied by id is set
170 _SQUID_INLINE_
bool isSet(HttpHdrCcType id
) const;
172 void packInto(Packable
* p
) const;
174 /** bit-mask representing what header values are set among those
175 * recognized by squid.
177 * managed via EBIT_SET/TEST/CLR
184 int32_t stale_if_error
;
186 String private_
; ///< List of headers sent as value for CC:private="...". May be empty/undefined if the value is missing.
187 String no_cache
; ///< List of headers sent as value for CC:no-cache="...". May be empty/undefined if the value is missing.
189 /// low-level part of the public set method, performs no checks
190 _SQUID_INLINE_
void setMask(HttpHdrCcType id
, bool newval
=true);
191 _SQUID_INLINE_
void setValue(int32_t &value
, int32_t new_value
, HttpHdrCcType hdr
, bool setting
=true);
194 /**comma-separated representation of the header values which were
195 * received but are not recognized.
203 void httpHdrCcInitModule(void);
204 void httpHdrCcUpdateStats(const HttpHdrCc
* cc
, StatHist
* hist
);
205 void httpHdrCcStatDumper(StoreEntry
* sentry
, int idx
, double val
, double size
, int count
);
208 operator<< (std::ostream
&, HttpHdrCcType
);
211 #include "HttpHdrCc.cci"
214 #endif /* SQUID_HTTPHDRCC_H */