HttpHdrCc.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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 "defines.h"
13#include "dlink.h"
14#include "mem/forward.h"
15#include "SquidString.h"
16#include <iosfwd>
17
18class Packable;
19
20enum HttpHdrCcType : unsigned char {
34 CC_IMMUTABLE, /* RFC 8246 */
36 CC_ENUM_END /* also used to mean "invalid" */
37};
38
44{
46
47public:
48 static const int32_t MAX_AGE_UNKNOWN=-1; //max-age is unset
49 static const int32_t S_MAXAGE_UNKNOWN=-1; //s-maxage is unset
50 static const int32_t MAX_STALE_UNKNOWN=-1; //max-stale is unset
53 static const int32_t MAX_STALE_ANY=0x7fffffff;
54 static const int32_t STALE_IF_ERROR_UNKNOWN=-1; //stale_if_error is unset
55 static const int32_t MIN_FRESH_UNKNOWN=-1; //min_fresh is unset
56
61
63 void clear();
64
66 bool parse(const String & s);
67
68 //manipulation for Cache-Control: public header
72
73 //manipulation for Cache-Control: private header
74 bool hasPrivate(const String **val = nullptr) const { return hasDirective(HttpHdrCcType::CC_PRIVATE, &private_, val); }
75 void Private(const String &v) {
77 if (!v.size())
78 return;
79 // uses append for multi-line headers
80 if (private_.size() > 0)
81 private_.append(",");
83 }
85
86 //manipulation for Cache-Control: no-cache header
87 bool hasNoCacheWithParameters() const { return hasNoCache() && no_cache.size(); }
88 bool hasNoCacheWithoutParameters() const { return hasNoCache() && !no_cache.size(); }
89 bool hasNoCache(const String **val = nullptr) const { return hasDirective(HttpHdrCcType::CC_NO_CACHE, &no_cache, val); }
90 void noCache(const String &v) {
92 if (!v.size())
93 return;
94 // uses append for multi-line headers
95 if (no_cache.size() > 0 && v.size() > 0)
96 no_cache.append(",");
98 }
100
101 //manipulation for Cache-Control: no-store header
105
106 //manipulation for Cache-Control: no-transform header
110
111 //manipulation for Cache-Control: must-revalidate header
115
116 //manipulation for Cache-Control: proxy-revalidate header
120
121 //manipulation for Cache-Control: max-age header
122 bool hasMaxAge(int32_t *val = nullptr) const { return hasDirective(HttpHdrCcType::CC_MAX_AGE, max_age, val); }
125
126 //manipulation for Cache-Control: s-maxage header
127 bool hasSMaxAge(int32_t *val = nullptr) const { return hasDirective(HttpHdrCcType::CC_S_MAXAGE, s_maxage, val); }
130
131 //manipulation for Cache-Control: max-stale header
132 bool hasMaxStale(int32_t *val = nullptr) const { return hasDirective(HttpHdrCcType::CC_MAX_STALE, max_stale, val); }
133 // max-stale has a special value (MAX_STALE_ANY) which correspond to having
134 // the directive without a numeric specification, and directs to consider the object
135 // as always-expired.
138
139 //manipulation for Cache-Control:min-fresh header
140 bool hasMinFresh(int32_t *val = nullptr) const { return hasDirective(HttpHdrCcType::CC_MIN_FRESH, min_fresh, val); }
141 void minFresh(int32_t v) {if (v < 0) return; setValue(min_fresh,v,HttpHdrCcType::CC_MIN_FRESH); }
143
144 //manipulation for Cache-Control: only-if-cached header
148
149 //manipulation for Cache-Control: stale-if-error header
150 bool hasStaleIfError(int32_t *val = nullptr) const { return hasDirective(HttpHdrCcType::CC_STALE_IF_ERROR, stale_if_error, val); }
153
154 //manipulation for Cache-Control: immutable header
158
160 bool isSet(HttpHdrCcType id) const {
162 return EBIT_TEST(mask, static_cast<long>(id));
163 }
164
165 void packInto(Packable * p) const;
166
172private:
173 int32_t mask;
174 int32_t max_age;
175 int32_t s_maxage;
176 int32_t max_stale;
178 int32_t min_fresh;
181
183 template<class Value>
184 bool hasDirective(const HttpHdrCcType hdrType, const Value &parsedVal, Value *outVal = nullptr) const {
185 if (isSet(hdrType)) {
186 if (outVal)
187 *outVal = parsedVal;
188 return true;
189 }
190 return false;
191 }
192
194 void setMask(HttpHdrCcType id, bool newval=true) {
195 if (newval)
196 EBIT_SET(mask,static_cast<long>(id));
197 else
198 EBIT_CLR(mask, static_cast<long>(id));
199 }
200
201 void setValue(int32_t &value, int32_t new_value, HttpHdrCcType hdr, bool setting=true);
202
203public:
208};
209
210class StatHist;
211class StoreEntry;
212
213void httpHdrCcInitModule(void);
214void httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist);
215void httpHdrCcStatDumper(StoreEntry * sentry, int idx, double val, double size, int count);
216
217std::ostream & operator<< (std::ostream &, HttpHdrCcType);
218
219#endif /* SQUID_HTTPHDRCC_H */
220
void httpHdrCcUpdateStats(const HttpHdrCc *cc, StatHist *hist)
Definition: HttpHdrCc.cc:321
HttpHdrCcType
Definition: HttpHdrCc.h:20
@ CC_MUST_REVALIDATE
Definition: HttpHdrCc.h:26
@ CC_S_MAXAGE
Definition: HttpHdrCc.h:29
@ CC_ONLY_IF_CACHED
Definition: HttpHdrCc.h:32
@ CC_OTHER
Definition: HttpHdrCc.h:35
@ CC_ENUM_END
Definition: HttpHdrCc.h:36
@ CC_NO_STORE
Definition: HttpHdrCc.h:24
@ CC_PUBLIC
Definition: HttpHdrCc.h:21
@ CC_PRIVATE
Definition: HttpHdrCc.h:22
@ CC_MAX_STALE
Definition: HttpHdrCc.h:30
@ CC_STALE_IF_ERROR
Definition: HttpHdrCc.h:33
@ CC_IMMUTABLE
Definition: HttpHdrCc.h:34
@ CC_PROXY_REVALIDATE
Definition: HttpHdrCc.h:27
@ CC_NO_CACHE
Definition: HttpHdrCc.h:23
@ CC_MAX_AGE
Definition: HttpHdrCc.h:28
@ CC_NO_TRANSFORM
Definition: HttpHdrCc.h:25
@ CC_MIN_FRESH
Definition: HttpHdrCc.h:31
void httpHdrCcInitModule(void)
Module initialization hook.
Definition: HttpHdrCc.cc:61
std::ostream & operator<<(std::ostream &, HttpHdrCcType)
Definition: HttpHdrCc.cc:344
void httpHdrCcStatDumper(StoreEntry *sentry, int idx, double val, double size, int count)
Definition: HttpHdrCc.cc:331
int size
Definition: ModDevPoll.cc:75
#define assert(EX)
Definition: assert.h:19
bool hasSMaxAge(int32_t *val=nullptr) const
Definition: HttpHdrCc.h:127
static const int32_t S_MAXAGE_UNKNOWN
Definition: HttpHdrCc.h:49
MEMPROXY_CLASS(HttpHdrCc)
bool hasNoStore() const
Definition: HttpHdrCc.h:102
void clear()
reset data-members to default state
Definition: HttpHdrCc.cc:70
bool hasDirective(const HttpHdrCcType hdrType, const Value &parsedVal, Value *outVal=nullptr) const
implements typical has*() method logic
Definition: HttpHdrCc.h:184
void staleIfError(int32_t v)
Definition: HttpHdrCc.h:151
String no_cache
List of headers sent as value for CC:no-cache="...". May be empty/undefined if the value is missing.
Definition: HttpHdrCc.h:180
bool hasMustRevalidate() const
Definition: HttpHdrCc.h:112
bool hasNoCache(const String **val=nullptr) const
Definition: HttpHdrCc.h:89
void mustRevalidate(bool v)
Definition: HttpHdrCc.h:113
void minFresh(int32_t v)
Definition: HttpHdrCc.h:141
static const int32_t MIN_FRESH_UNKNOWN
Definition: HttpHdrCc.h:55
void Private(const String &v)
Definition: HttpHdrCc.h:75
void clearMinFresh()
Definition: HttpHdrCc.h:142
void clearOnlyIfCached()
Definition: HttpHdrCc.h:147
bool hasMaxStale(int32_t *val=nullptr) const
Definition: HttpHdrCc.h:132
void Immutable(bool v)
Definition: HttpHdrCc.h:156
bool hasPrivate(const String **val=nullptr) const
Definition: HttpHdrCc.h:74
void clearNoTransform()
Definition: HttpHdrCc.h:109
void Public(bool v)
Definition: HttpHdrCc.h:70
void clearMustRevalidate()
Definition: HttpHdrCc.h:114
void noTransform(bool v)
Definition: HttpHdrCc.h:108
static const int32_t STALE_IF_ERROR_UNKNOWN
Definition: HttpHdrCc.h:54
void clearPrivate()
Definition: HttpHdrCc.h:84
bool hasNoCacheWithoutParameters() const
Definition: HttpHdrCc.h:88
void setMask(HttpHdrCcType id, bool newval=true)
low-level part of the public set method, performs no checks
Definition: HttpHdrCc.h:194
void clearProxyRevalidate()
Definition: HttpHdrCc.h:119
void maxAge(int32_t v)
Definition: HttpHdrCc.h:123
void clearPublic()
Definition: HttpHdrCc.h:71
bool parse(const String &s)
parse a header-string and fill in appropriate values.
Definition: HttpHdrCc.cc:95
bool hasMinFresh(int32_t *val=nullptr) const
Definition: HttpHdrCc.h:140
bool hasPublic() const
Definition: HttpHdrCc.h:69
void clearMaxAge()
Definition: HttpHdrCc.h:124
bool isSet(HttpHdrCcType id) const
check whether the attribute value supplied by id is set
Definition: HttpHdrCc.h:160
String private_
List of headers sent as value for CC:private="...". May be empty/undefined if the value is missing.
Definition: HttpHdrCc.h:179
int32_t max_stale
Definition: HttpHdrCc.h:176
void onlyIfCached(bool v)
Definition: HttpHdrCc.h:146
void clearSMaxAge()
Definition: HttpHdrCc.h:129
static const int32_t MAX_STALE_ANY
Definition: HttpHdrCc.h:53
void noCache(const String &v)
Definition: HttpHdrCc.h:90
bool hasOnlyIfCached() const
Definition: HttpHdrCc.h:145
void setValue(int32_t &value, int32_t new_value, HttpHdrCcType hdr, bool setting=true)
Definition: HttpHdrCc.cc:78
static const int32_t MAX_STALE_UNKNOWN
Definition: HttpHdrCc.h:50
void clearNoStore()
Definition: HttpHdrCc.h:104
int32_t mask
Definition: HttpHdrCc.h:173
bool hasImmutable() const
Definition: HttpHdrCc.h:155
int32_t min_fresh
Definition: HttpHdrCc.h:178
void clearStaleIfError()
Definition: HttpHdrCc.h:152
void clearMaxStale()
Definition: HttpHdrCc.h:137
static const int32_t MAX_AGE_UNKNOWN
Definition: HttpHdrCc.h:48
bool hasMaxAge(int32_t *val=nullptr) const
Definition: HttpHdrCc.h:122
bool hasProxyRevalidate() const
Definition: HttpHdrCc.h:117
bool hasNoCacheWithParameters() const
Definition: HttpHdrCc.h:87
void clearNoCache()
Definition: HttpHdrCc.h:99
int32_t max_age
Definition: HttpHdrCc.h:174
HttpHdrCc()
Definition: HttpHdrCc.h:57
void noStore(bool v)
Definition: HttpHdrCc.h:103
String other
Definition: HttpHdrCc.h:207
void maxStale(int32_t v)
Definition: HttpHdrCc.h:136
void proxyRevalidate(bool v)
Definition: HttpHdrCc.h:118
bool hasStaleIfError(int32_t *val=nullptr) const
Definition: HttpHdrCc.h:150
void sMaxAge(int32_t v)
Definition: HttpHdrCc.h:128
int32_t s_maxage
Definition: HttpHdrCc.h:175
void packInto(Packable *p) const
Definition: HttpHdrCc.cc:247
bool hasNoTransform() const
Definition: HttpHdrCc.h:107
void clearImmutable()
Definition: HttpHdrCc.h:157
int32_t stale_if_error
Definition: HttpHdrCc.h:177
void clean()
Definition: String.cc:118
void append(char const *buf, int len)
Definition: String.cc:149
size_type size() const
Definition: SquidString.h:73
#define EBIT_CLR(flag, bit)
Definition: defines.h:68
#define EBIT_SET(flag, bit)
Definition: defines.h:67
#define EBIT_TEST(flag, bit)
Definition: defines.h:69

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors