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 {
23 public:
24 using CookiesMap =
25 std::unordered_map<std::string, Cookie, utils::StrCaseHash>;
26
27 static std::optional<Cookie> FromString(std::string_view cookie_str);
28
29 Cookie(std::string name, std::string value);
30 Cookie(Cookie&& cookie) noexcept;
31 Cookie(const Cookie& cookie);
32 ~Cookie() noexcept;
33
34 Cookie& operator=(Cookie&&) noexcept;
35 Cookie& operator=(const Cookie& cookie);
36
37 const std::string& Name() const;
38 const std::string& Value() const;
39
40 bool IsSecure() const;
41 Cookie& SetSecure();
42
43 std::chrono::system_clock::time_point Expires() const;
44 Cookie& SetExpires(std::chrono::system_clock::time_point value);
45
46 bool IsPermanent() const;
47 Cookie& SetPermanent();
48
49 bool IsHttpOnly() const;
50 Cookie& SetHttpOnly();
51
52 const std::string& Path() const;
53 Cookie& SetPath(std::string value);
54
55 const std::string& Domain() const;
56 Cookie& SetDomain(std::string value);
57
58 std::chrono::seconds MaxAge() const;
59 Cookie& SetMaxAge(std::chrono::seconds value);
60
61 std::string SameSite() const;
62 Cookie& SetSameSite(std::string value);
63
64 std::string ToString() const;
65
66 void AppendToString(
67 USERVER_NAMESPACE::http::headers::HeadersString& os) const;
68
69 private:
70 class CookieData;
71 std::unique_ptr<CookieData> data_;
72};
73
74} // namespace server::http
75
76USERVER_NAMESPACE_END