This is a multimap (name is key) of cookies that is used for both requests and responses. For requests the insert(const std::string&) method is called automatically by general_hdr, for responses the application must call insert to create a cookie.
When inserting (for response) there is a constraint that the cookie ids must be unique. The general_hdr "Set-Cookie" field is automatically updated with each insert.
Follows RFC2109 standard, but parses Netscape as well (see insert).
Public Types | |
|
typedef std::multimap< std::string, cookie > | multimap_type |
| multimap type | |
| typedef multimap_type::const_iterator | const_iterator |
| iterator | |
Public Member Functions | |
| cookies (bool is_request) | |
| Construct. | |
| bool | empty () const |
| Test if empty. | |
| void | clear () |
| const_iterator | find (const std::string &name) const |
| Find start of cookies with given name, returning end() if none. | |
| bool | insert (const cookie &c) |
| Insert cookie, returning whether the id is new/cookie inserted. | |
| bool | insert (const std::string &v) |
| std::ostream & | operator<< (std::ostream &os) const |
| Stream out in HTTP header format. | |
| const_iterator | begin () const |
| Get multimap beginning. | |
| const_iterator | end () const |
| Get multimap end. | |
| void | attach (observer *o) |
| Attach observer (must outlive this). | |
| void | detach (observer *o) |
| Detach observer. | |
Static Public Attributes | |
| static const char | SEPARATOR_CSTR [3] |
| separator cstr (", ") | |
Classes | |
| struct | observer |
| Cookies observer interface. More... | |
| void restcgi::cookies::clear | ( | ) |
Clear all cookies.
| bool restcgi::cookies::insert | ( | const std::string & | v | ) |
Parse the "Cookie" header string into individual cookies and insert into collection. RFC2109 syntax almost supports Netscape. This uses a modified syntax to allow Netscape by not requiring a cookie-version and not forcing VALUE to be quoted-text. Note that the cookies are always inserted, if found, whether the whole string completely parses or not, which is the returned indication.
RFC2109 modified syntax:
cookies = [cookie-ver ";"] cookie-value *((";" | ",") cookie-value)
cookie-value = NAME "=" VALUE [";" path] [";" domain]
cookie-ver = "$Version" "=" value
NAME = attr
VALUE = <value or up to ";" or ",">
path = "$Path" "=" value
domain = "$Domain" "=" value
1.4.7