Panda3D
httpCookie.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file httpCookie.I
10  * @author drose
11  * @date 2004-08-26
12  */
13 
14 /**
15  * Constructs an empty cookie.
16  */
17 INLINE HTTPCookie::
18 HTTPCookie() :
19  _secure(false)
20 {
21 }
22 
23 /**
24  * Constructs a cookie according to the indicated string, presumably the tag
25  * of a Set-Cookie header. There is no way to detect a formatting error in
26  * the string with this constructor.
27  */
28 INLINE HTTPCookie::
29 HTTPCookie(const std::string &format, const URLSpec &url) {
30  parse_set_cookie(format, url);
31 }
32 
33 /**
34  * Constructs a cookie with the indicated name, path, and domain values, but
35  * no other data. This is most useful for looking up an existing cookie in
36  * the HTTPClient.
37  */
38 INLINE HTTPCookie::
39 HTTPCookie(const std::string &name, const std::string &path, const std::string &domain) :
40  _name(name),
41  _path(path),
42  _domain(domain),
43  _secure(false)
44 {
45 }
46 
47 /**
48  *
49  */
50 INLINE HTTPCookie::
51 ~HTTPCookie() {
52 }
53 
54 /**
55  *
56  */
57 INLINE void HTTPCookie::
58 set_name(const std::string &name) {
59  _name = name;
60 }
61 
62 /**
63  * Returns the name of the cookie. This is the key value specified by the
64  * server.
65  */
66 INLINE const std::string &HTTPCookie::
67 get_name() const {
68  return _name;
69 }
70 
71 /**
72  *
73  */
74 INLINE void HTTPCookie::
75 set_value(const std::string &value) {
76  _value = value;
77 }
78 
79 /**
80  * Returns the value of the cookie. This is the arbitrary string associated
81  * with the cookie's name, as specified by the server.
82  */
83 INLINE const std::string &HTTPCookie::
84 get_value() const {
85  return _value;
86 }
87 
88 /**
89  *
90  */
91 INLINE void HTTPCookie::
92 set_domain(const std::string &domain) {
93  _domain = domain;
94 }
95 
96 /**
97  *
98  */
99 INLINE const std::string &HTTPCookie::
100 get_domain() const {
101  return _domain;
102 }
103 
104 /**
105  *
106  */
107 INLINE void HTTPCookie::
108 set_path(const std::string &path) {
109  _path = path;
110 }
111 
112 /**
113  * Returns the prefix of the URL paths on the server for which this cookie
114  * will be sent.
115  */
116 INLINE const std::string &HTTPCookie::
117 get_path() const {
118  return _path;
119 }
120 
121 /**
122  *
123  */
124 INLINE void HTTPCookie::
125 set_expires(const HTTPDate &expires) {
126  _expires = expires;
127 }
128 
129 /**
130  * Removes the expiration date on the cookie.
131  */
132 INLINE void HTTPCookie::
133 clear_expires() {
134  _expires = HTTPDate();
135 }
136 
137 /**
138  * Returns true if the cookie has an expiration date, false otherwise.
139  */
140 INLINE bool HTTPCookie::
141 has_expires() const {
142  return _expires.is_valid();
143 }
144 
145 /**
146  * Returns the expiration date of the cookie if it is set, or an invalid date
147  * if it is not.
148  */
149 INLINE HTTPDate HTTPCookie::
150 get_expires() const {
151  return _expires;
152 }
153 
154 /**
155  *
156  */
157 INLINE void HTTPCookie::
158 set_secure(bool secure) {
159  _secure = secure;
160 }
161 
162 /**
163  * Returns true if the server has indicated this is a "secure" cookie which
164  * should only be sent over an HTTPS channel.
165  */
166 INLINE bool HTTPCookie::
167 get_secure() const {
168  return _secure;
169 }
170 
171 /**
172  * Returns true if the cookie's expiration date is before the indicated date,
173  * false otherwise.
174  */
175 INLINE bool HTTPCookie::
176 is_expired(const HTTPDate &now) const {
177  return _expires.is_valid() && _expires < now;
178 }
179 
180 INLINE std::ostream &operator << (std::ostream &out, const HTTPCookie &cookie) {
181  cookie.output(out);
182  return out;
183 }
A container for a URL, e.g.
Definition: urlSpec.h:28
A container for an HTTP-legal time/date indication.
Definition: httpDate.h:27