1
+ #include < mochios/helpers/cookie.h>
2
+ #include < mochios/messages/cookie.h>
3
+
4
+ mochios::messages::Cookie::Cookie ()
5
+ : secure(false ), httpOnly(false ), partitioned(false ), name(" " ), value(" " ),
6
+ domain(" " ), path(" " ), expires(" " ), maxAge(" " ), sameSite(" " ) {
7
+ return ;
8
+ }
9
+
10
+ mochios::messages::Cookie::Cookie (const std::string &data) {
11
+ std::string key, value;
12
+ std::vector<std::string> kv;
13
+ std::vector<std::string> parts = brewtils::string::split (data, " ;" );
14
+
15
+ for (const std::string &part : parts) {
16
+ kv = brewtils::string::split (part, " =" );
17
+ if (kv.size () == 0 ) {
18
+ continue ;
19
+ }
20
+
21
+ key = brewtils::string::lower (
22
+ brewtils::url::decode (brewtils::string::trim (kv[0 ])));
23
+ if (kv.size () == 1 ) {
24
+ if (key == " secure" ) {
25
+ this ->secure = true ;
26
+ } else if (key == " httponly" ) {
27
+ this ->httpOnly = true ;
28
+ } else if (key == " partitioned" ) {
29
+ this ->partitioned = true ;
30
+ }
31
+ continue ;
32
+ }
33
+
34
+ value = brewtils::url::decode (brewtils::string::trim (kv[1 ]));
35
+ if (key == " domain" ) {
36
+ this ->domain = value;
37
+ } else if (key == " path" ) {
38
+ this ->path = value;
39
+ } else if (key == " expires" ) {
40
+ this ->expires = value;
41
+ } else if (key == " max-age" ) {
42
+ this ->maxAge = value;
43
+ } else if (key == " samesite" ) {
44
+ this ->sameSite = value;
45
+ } else {
46
+ this ->name = brewtils::url::decode (brewtils::string::trim (kv[0 ]));
47
+ this ->value = value;
48
+ }
49
+ }
50
+
51
+ if (this ->name .empty ()) {
52
+ logger::warning (" Cookie name empty in data: " + data);
53
+ }
54
+
55
+ return ;
56
+ }
57
+
58
+ mochios::messages::Cookie::~Cookie () { return ; }
59
+
60
+ std::string mochios::messages::Cookie::serialize () const {
61
+ return mochios::helpers::cookie::serialize (*this );
62
+ }
0 commit comments