Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
Cookie.h
浏览该文件的文档.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
23#pragma once
24
25#include <sese/Config.h>
26
27#ifdef SESE_PLATFORM_WINDOWS
28#pragma warning(disable : 4251)
29#endif
30
31namespace sese::net::http {
32
34class Cookie {
35public:
36 using Ptr = std::shared_ptr<Cookie>;
37
38 explicit Cookie(const std::string &name) noexcept;
39 Cookie(const std::string &name, const std::string &value) noexcept;
40
41public:
42 [[nodiscard]] bool expired(uint64_t now) const;
43
44 [[nodiscard]] bool isSecure() const;
45 void setSecure(bool secure);
46 [[nodiscard]] bool isHttpOnly() const;
47 void setHttpOnly(bool http_only);
48 [[nodiscard]] uint64_t getMaxAge() const;
49 void setMaxAge(uint64_t max_age);
50 [[nodiscard]] uint64_t getExpires() const;
51 void setExpires(uint64_t expires);
52 [[nodiscard]] const std::string &getName() const;
53 [[nodiscard]] const std::string &getValue() const;
54 void setValue(const std::string &value);
55 [[nodiscard]] const std::string &getDomain() const;
56 void setDomain(const std::string &domain);
57 [[nodiscard]] const std::string &getPath() const;
58 void setPath(const std::string &path);
59
60 void updateExpiresFrom(uint64_t now);
61
62private:
63 bool secure = false;
64 bool httpOnly = false;
65
66 uint64_t maxAge = 0;
67 uint64_t expires = 0;
68
69 std::string name;
70 std::string value;
71 std::string domain;
72 std::string path;
73};
74} // namespace sese::net::http