/** ================================* eli960@qq.com* http:/linuxmail.cn/* 2017年07月22日* ================================*/#include "zcc/zcc_http.h"#include <cctype>zcc_namespace_begin;std::map<std::string, std::string> http_cookie_parse(const char *raw_cookie){std::map<std::string, std::string> r;const char *q, *p, *ps = raw_cookie;std::string name, value;while (1){while (*ps){if ((*ps == ' ') || (*ps == '\t')){ps++;continue;}break;}p = ps;while ((*p != '0円') && (*p != ';')){p++;}do{q = ps;while (q < p){if (*q == '='){break;}q++;}if (q == p){break;}name.clear();name.append(ps, q - ps);value.clear();q++;http_token_decode(q, (int)(p - q), value);} while (0);r[name] = value;if (*p == '0円'){break;}ps = p + 1;}return r;}std::string http_cookie_build_item(const char *name, const char *value, int64_t expires, const char *path, const char *domain, bool secure, bool httponly){unsigned char dec2hex[18] = "0123456789ABCDEF";std::string r;int ch;const unsigned char *p;r.append(name).append("=");if (empty(value)){r.append("deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0;");return r;}// valuer.append(http_token_encode(value, true));if (expires > 0){r.append("; expires=").append(rfc7231_time(expires));r.append("; Max-Age=").append(std::to_string(expires - second()));}if (!empty(path)){r.append("; path=");// pathp = (const unsigned char *)path;while ((ch = *p++)){if (std::isalnum(ch) || (ch == '/')){r.push_back((char)ch);}else{r.push_back('%');r.push_back(dec2hex[ch >> 4]);r.push_back(dec2hex[ch & 0X0F]);}}}if (!empty(domain)){r.append("; domain=");// domainr.append(http_token_encode(domain, true));}if (secure){r.append("; secure");}if (httponly){r.append("; httponly");}return r;}zcc_namespace_end;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型