VWeb/Includes/Cookie.h
Maurice Grönwoldt 5bb68a7d02 Split VWeb into smaller headers
We have no make install support... so we don't need to have everything as a single-header and lib file.
2023-09-16 16:29:03 +02:00

35 lines
956 B
C++

#pragma once
#include <string>
#include <unordered_map>
namespace VWeb {
enum class CookieSameSite { Invalid = 0, Strict, Lax, None };
struct Cookie {
std::string Name{};
std::string Value{};
std::string Expires{};
int MaxAge{};
std::string Domain{};
std::string Path{"/"};
bool Secure{};
bool HttpOnly{};
CookieSameSite SameSite{CookieSameSite::Strict};
bool IsOld = false;
};
struct Cookies {
public:
void Remove(const std::string &name);
bool Has(const std::string &name) const;
Cookie &Get(const std::string &name) { return Data[name]; };
std::string TransformToHeader();
void CreateCookieFromString(const std::string &data);
void CreateOld(const std::string &name, const std::string &value);
std::unordered_map<std::string, Cookie> Data;
Cookie &operator[](const std::string &name) { return Data[name]; }
protected:
static void CookieToString(std::stringstream &stream, Cookie &cookie);
};
} // namespace VWeb