Line data Source code
1 : // Snap Websites Servers -- parse and memorize cache control settings
2 : // Copyright (c) 2011-2019 Made to Order Software Corp. All Rights Reserved
3 : //
4 : // This program is free software; you can redistribute it and/or modify
5 : // it under the terms of the GNU General Public License as published by
6 : // the Free Software Foundation; either version 2 of the License, or
7 : // (at your option) any later version.
8 : //
9 : // This program is distributed in the hope that it will be useful,
10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : // GNU General Public License for more details.
13 : //
14 : // You should have received a copy of the GNU General Public License
15 : // along with this program; if not, write to the Free Software
16 : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 : #pragma once
18 :
19 : // Qt lib
20 : //
21 : #include <QString>
22 :
23 : // C++ lib
24 : //
25 : #include <set>
26 :
27 :
28 :
29 : namespace snap
30 : {
31 :
32 :
33 0 : class cache_control_settings
34 : {
35 : public:
36 : typedef std::set<std::string> fields_t;
37 : typedef std::set<std::string> tags_t;
38 :
39 : // From spec: "HTTP/1.1 servers SHOULD NOT send Expires dates
40 : // more than one year in the future."
41 : //
42 : static int64_t const AGE_MAXIMUM = 365 * 24 * 60 * 60;
43 : static int64_t const IGNORE_VALUE = -1;
44 :
45 : cache_control_settings();
46 : cache_control_settings(QString const & info, bool const internal_setup);
47 :
48 : // general handling
49 : void reset_cache_info();
50 : void set_cache_info(QString const & info, bool const internal_setup);
51 :
52 : // response only (server)
53 : void set_must_revalidate(bool const must_revalidate);
54 : bool get_must_revalidate() const;
55 :
56 : void set_private(bool const private_cache);
57 : bool get_private() const;
58 :
59 : void set_proxy_revalidate(bool const proxy_revalidate);
60 : bool get_proxy_revalidate() const;
61 :
62 : void set_immutable(bool const immutable);
63 : bool get_immutable() const;
64 :
65 : void set_public(bool const public_cache);
66 : bool get_public() const;
67 :
68 : void add_revalidate_field_name(std::string const & field_name);
69 : void add_revalidate_field_name(QString const & field_name);
70 : void add_revalidate_field_name(char const * field_name);
71 : fields_t const & get_revalidate_field_names() const;
72 :
73 : void add_private_field_name(std::string const & field_name);
74 : void add_private_field_name(QString const & field_name);
75 : void add_private_field_name(char const * field_name);
76 : fields_t const & get_private_field_names() const;
77 :
78 : void add_tag(std::string const & tag_name);
79 : void add_tag(QString const & tag_name);
80 : void add_tag(char const * tag_name);
81 : tags_t const & get_tags() const;
82 :
83 : // request and response (client and server)
84 : void set_max_age(int64_t const max_age);
85 : void set_max_age(QString const & max_age);
86 : void update_max_age(int64_t max_age);
87 : int64_t get_max_age() const;
88 :
89 : void set_no_cache(bool const no_cache);
90 : bool get_no_cache() const;
91 :
92 : void set_no_store(bool const no_store);
93 : bool get_no_store() const;
94 :
95 : void set_no_transform(bool const no_transform);
96 : bool get_no_transform() const;
97 :
98 : void set_s_maxage(int64_t const s_maxage);
99 : void set_s_maxage(QString const & s_maxage);
100 : void update_s_maxage(int64_t s_maxage);
101 : int64_t get_s_maxage() const;
102 :
103 : // request only (client)
104 : void set_max_stale(int64_t const max_stale);
105 : void set_max_stale(QString const & max_stale);
106 : int64_t get_max_stale() const;
107 :
108 : void set_min_fresh(int64_t const min_fresh);
109 : void set_min_fresh(QString const & min_fresh);
110 : int64_t get_min_fresh() const;
111 :
112 : void set_only_if_cached(bool const only_if_cached);
113 : bool get_only_if_cached() const;
114 :
115 : // utility functions
116 : static int64_t string_to_seconds(QString const & max_age);
117 : static int64_t minimum(int64_t const a, int64_t const b);
118 :
119 : private:
120 : // in alphabetical order
121 : bool f_immutable = false;
122 : int64_t f_max_age = 0;
123 : int64_t f_max_stale = IGNORE_VALUE;
124 : int64_t f_min_fresh = IGNORE_VALUE;
125 : bool f_must_revalidate = true;
126 : bool f_no_cache = false;
127 : bool f_no_store = false;
128 : bool f_no_transform = false;
129 : bool f_only_if_cached = false;
130 : bool f_private = false;
131 : fields_t f_private_field_names = { "Set-Cookie" };
132 : bool f_proxy_revalidate = false;
133 : bool f_public = false;
134 : fields_t f_revalidate_field_names = fields_t();
135 : int64_t f_s_maxage = IGNORE_VALUE;
136 : tags_t f_tags = tags_t();
137 : };
138 :
139 :
140 : } // namespace snap
141 : // vim: ts=4 sw=4 et
|