-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCookie.h
49 lines (39 loc) · 1.09 KB
/
Cookie.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include <string>
#include <ctime>
#include <sstream>
#include <iomanip>
struct Cookie {
Cookie(const std::string &name, const std::string &value, const std::time_t &expires, const std::string &path,
const std::size_t &maxAge) {
Name = name;
Value = value;
Expires = expires;
Path = path;
MaxAge = maxAge;
}
Cookie(const std::string &name, const std::string &value) {
Name = name;
Value = value;
HasExpires = false;
Path = "";
MaxAge = 0;
}
std::string Name;
std::string Value;
std::time_t Expires;
bool HasExpires;
std::string Path;
std::size_t MaxAge;
std::string ToString() {
std::stringstream rtn;
rtn << Name << '=' << Value << ';';
if (HasExpires)
rtn << std::put_time(std::gmtime(&Expires), "%a, %d %m %Y %T GMT")<< ';';
if (MaxAge != 0)
rtn << "Max-Age=" << std::to_string(MaxAge)<< ';';
if (!Path.empty())
rtn << "Path=" << Path<< ';';
return rtn.str();
}
};