Prechádzať zdrojové kódy

fix #324: Add HttpCookie::priority

ithewei 3 rokov pred
rodič
commit
2584ee10a2
2 zmenil súbory, kde vykonal 29 pridanie a 8 odobranie
  1. 22 8
      http/HttpMessage.cpp
  2. 7 0
      http/HttpMessage.h

+ 22 - 8
http/HttpMessage.cpp

@@ -46,6 +46,12 @@ bool HttpCookie::parse(const std::string& str) {
                             stricmp(val.c_str(), "None")   == 0 ? HttpCookie::SameSite::None   :
                             stricmp(val.c_str(), "None")   == 0 ? HttpCookie::SameSite::None   :
                                                                   HttpCookie::SameSite::Default;
                                                                   HttpCookie::SameSite::Default;
             }
             }
+            else if (stricmp(pkey, "Priority") == 0) {
+                priority =  stricmp(val.c_str(), "Low")    == 0 ? HttpCookie::Priority::Low    :
+                            stricmp(val.c_str(), "Medium") == 0 ? HttpCookie::Priority::Medium :
+                            stricmp(val.c_str(), "High")   == 0 ? HttpCookie::Priority::High   :
+                                                                  HttpCookie::Priority::NotSet ;
+            }
             else {
             else {
                 if (name.empty()) {
                 if (name.empty()) {
                     name = key;
                     name = key;
@@ -75,19 +81,20 @@ std::string HttpCookie::dump() const {
     assert(!name.empty() || !kv.empty());
     assert(!name.empty() || !kv.empty());
     std::string res;
     std::string res;
 
 
-    if (!kv.empty()) {
-        for (auto& pair : kv) {
-            if (!res.empty()) res += "; ";
-            res += pair.first;
-            res += "=";
-            res += pair.second;
-        }
-    } else {
+    if (!name.empty()) {
         res = name;
         res = name;
         res += "=";
         res += "=";
         res += value;
         res += value;
     }
     }
 
 
+    for (auto& pair : kv) {
+        if (pair.first == name) continue;
+        if (!res.empty()) res += "; ";
+        res += pair.first;
+        res += "=";
+        res += pair.second;
+    }
+
     if (!domain.empty()) {
     if (!domain.empty()) {
         res += "; Domain=";
         res += "; Domain=";
         res += domain;
         res += domain;
@@ -113,6 +120,13 @@ std::string HttpCookie::dump() const {
                                                           "None"   ;
                                                           "None"   ;
     }
     }
 
 
+    if (priority != HttpCookie::Priority::NotSet) {
+        res += "; Priority=";
+        res += priority == HttpCookie::Priority::Low    ? "Low"    :
+               priority == HttpCookie::Priority::Medium ? "Medium" :
+                                                          "High"   ;
+    }
+
     if (secure) {
     if (secure) {
         res += "; Secure";
         res += "; Secure";
     }
     }

+ 7 - 0
http/HttpMessage.h

@@ -76,6 +76,12 @@ struct HV_EXPORT HttpCookie {
         Lax,
         Lax,
         None
         None
     } samesite;
     } samesite;
+    enum Priority {
+        NotSet,
+        Low,
+        Medium,
+        High,
+    } priority;
     hv::KeyValue kv; // for multiple names
     hv::KeyValue kv; // for multiple names
 
 
     HttpCookie() {
     HttpCookie() {
@@ -87,6 +93,7 @@ struct HV_EXPORT HttpCookie {
         secure = false;
         secure = false;
         httponly = false;
         httponly = false;
         samesite = Default;
         samesite = Default;
+        priority = NotSet;
     }
     }
 
 
     void reset() {
     void reset() {