|
NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
|
HTTP Cookie结构 更多...
#include <http_session.hpp>
Public 成员函数 | |
| string | to_string () const |
| 序列化为Set-Cookie头 | |
| bool | is_valid () const noexcept |
| 检查Cookie是否有效 | |
| bool | is_expired () const noexcept |
| 检查Cookie是否已过期 | |
| void | set_expires_from_now (seconds sec) |
| 设置从当前时间开始计算的过期时间 | |
| Public 成员函数 继承自 iobject< http_cookie > | |
| constexpr bool | try_parse (const string_view str) noexcept |
| 尝试从字符串解析对象 | |
| Public 成员函数 继承自 istringify< http_cookie > | |
| constexpr string | to_string () const |
| 转换为字符串 | |
静态 Public 成员函数 | |
| static http_cookie | parse (string_view header) |
| 解析Set-Cookie头 | |
| static http_cookie | parse (string_view header, string default_domain, string default_path) |
| 解析Set-Cookie头(带默认值) | |
| 静态 Public 成员函数 继承自 iobject< http_cookie > | |
| static constexpr http_cookie | parse (const string_view str) |
| 从字符串解析对象 | |
Public 属性 | |
| http_cookie_name | name |
| Cookie名称 | |
| string | value |
| Cookie值 | |
| string | domain |
| Domain | |
| string | path {"/"} |
| Path | |
| seconds | max_age {-1} |
| Max-Age(-1表示会话Cookie) | |
| bool | secure {false} |
| Secure(仅HTTPS) | |
| bool | http_only {false} |
| HttpOnly(禁止JS) | |
| string | same_site {http_key::Strict()} |
| SameSite | |
| datetime | expires |
| Expires | |
HTTP Cookie结构
表示一个HTTP Cookie,包含名称、值以及各种属性。 支持解析Set-Cookie头和序列化为Set-Cookie头格式。
Cookie属性说明:
使用示例:
在文件 http_session.hpp 第 62 行定义.
|
nodiscardnoexcept |
检查Cookie是否已过期
根据Max-Age或Expires判断Cookie是否已过期。 会话Cookie(max_age = -1)永不过期。
引用了 is_expired().
被这些函数引用 is_expired().
|
nodiscardnoexcept |
检查Cookie是否有效
|
staticnodiscard |
解析Set-Cookie头
| header | Set-Cookie头的值 |
解析Set-Cookie头字符串,提取Cookie名称、值和属性。
|
staticnodiscard |
解析Set-Cookie头(带默认值)
| header | Set-Cookie头的值 |
| default_domain | 默认Domain值 |
| default_path | 默认Path值 |
解析Set-Cookie头,如果未指定Domain或Path,使用提供的默认值。
| void http_cookie::set_expires_from_now | ( | seconds | sec | ) |
设置从当前时间开始计算的过期时间
| sec | 有效期 |
设置Expires为当前时间 + seconds。 同时设置max_age = seconds。
被这些函数引用 set_expires_from_now().
|
nodiscard |
序列化为Set-Cookie头
将Cookie对象转换为Set-Cookie头的格式。