userver: userver/server/http/http_response_cookie.hpp Source File
Loading...
Searching...
No Matches
http_response_cookie.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/http/http_response_cookie.hpp
4/// @brief @copybrief server::http::Cookie
5
6#include <chrono>
7#include <memory>
8#include <optional>
9#include <string>
10#include <unordered_map>
11
12#include <userver/http/predefined_header.hpp>
13#include <userver/utils/str_icase.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace server::http {
18
19/// @ingroup userver_containers
20///
21/// @brief HTTP response cookie
22class Cookie final {
23public:
24 using CookiesMap = std::unordered_map<std::string, Cookie, utils::StrCaseHash>;
25
26 static std::optional<Cookie> FromString(std::string_view cookie_str);
27
28 Cookie(std::string name, std::string value);
29 Cookie(Cookie&& cookie) noexcept;
30 Cookie(const Cookie& cookie);
31 ~Cookie() noexcept;
32
33 Cookie& operator=(Cookie&&) noexcept;
34 Cookie& operator=(const Cookie& cookie);
35
36 const std::string& Name() const;
37 const std::string& Value() const;
38
39 bool IsSecure() const;
40 Cookie& SetSecure();
41
42 std::chrono::system_clock::time_point Expires() const;
43 Cookie& SetExpires(std::chrono::system_clock::time_point value);
44
45 bool IsPermanent() const;
46 Cookie& SetPermanent();
47
48 bool IsHttpOnly() const;
49 Cookie& SetHttpOnly();
50
51 const std::string& Path() const;
52 Cookie& SetPath(std::string value);
53
54 const std::string& Domain() const;
55 Cookie& SetDomain(std::string value);
56
57 std::chrono::seconds MaxAge() const;
58 Cookie& SetMaxAge(std::chrono::seconds value);
59
60 std::string SameSite() const;
61 Cookie& SetSameSite(std::string value);
62
63 std::string ToString() const;
64
65 void AppendToString(USERVER_NAMESPACE::http::headers::HeadersString& os) const;
66
67private:
68 class CookieData;
69 std::unique_ptr<CookieData> data_;
70};
71
72} // namespace server::http
73
74USERVER_NAMESPACE_END