Decentralised Art Server
High-performance C++ backend that exposes HTML interface and a secure REST API for managing Performative Transactions entities
 
Loading...
Searching...
No Matches
http_headers.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <format>
5#include <string>
6#include <vector>
7#include <string>
8#include <cctype>
9
10#include "utils.hpp"
11
12namespace dcn::http
13{
19 enum class Header
20 {
21 // Unknown, specially reserved
22 Unknown = 0,
23
24 Accept,
25
30
32
37
38 Cookie,
39 Date,
40 Expect,
41
42 Origin,
43
45
47 };
48
54 using HeadersList = std::vector<std::pair<Header, std::string>>;
55}
56
57namespace dcn::parse
58{
65}
66
67template <>
68struct std::formatter<dcn::http::Header> : std::formatter<std::string> {
69 auto format(dcn::http::Header header, format_context& ctx) const {
70 switch(header)
71 {
72 // A
73 case dcn::http::Header::Accept: return formatter<string>::format("Accept", ctx);
74 case dcn::http::Header::AccessControlAllowOrigin: return formatter<string>::format("Access-Control-Allow-Origin", ctx);
75 case dcn::http::Header::AccessControlAllowMethods: return formatter<string>::format("Access-Control-Allow-Methods", ctx);
76 case dcn::http::Header::AccessControlAllowHeaders: return formatter<string>::format("Access-Control-Allow-Headers", ctx);
77 case dcn::http::Header::AccessControlAllowCredentials: return formatter<string>::format("Access-Control-Allow-Credentials", ctx);
78 case dcn::http::Header::Authorization: return formatter<string>::format("Authorization", ctx);
79
80 // B
81
82 // C
83 case dcn::http::Header::Connection: return formatter<string>::format("Connection", ctx);
84 case dcn::http::Header::ContentEncoding: return formatter<string>::format("Content-Encoding", ctx);
85 case dcn::http::Header::ContentLength: return formatter<string>::format("Content-Length", ctx);
86 case dcn::http::Header::ContentType: return formatter<string>::format("Content-Type", ctx);
87 case dcn::http::Header::Cookie: return formatter<string>::format("Cookie", ctx);
88
89 // D
90 case dcn::http::Header::Date: return formatter<string>::format("Date", ctx);
91
92 // O
93 case dcn::http::Header::Origin: return formatter<string>::format("Origin", ctx);
94
95 // S
96 case dcn::http::Header::SetCookie: return formatter<string>::format("Set-Cookie", ctx);
97
98 //X
99 case dcn::http::Header::XRefreshToken: return formatter<string>::format("X-Refresh-Token", ctx);
100
101 // Unknown
102 case dcn::http::Header::Unknown: return formatter<string>::format("Unknown", ctx);
103 }
104 return formatter<string>::format("", ctx);
105 }
106};
107
108template <>
109struct std::formatter<dcn::http::HeadersList> : std::formatter<std::string> {
110 auto format(dcn::http::HeadersList headers_list, format_context& ctx) const {
111 std::string headers_str = "";
112 for(const auto& [header, header_value] : headers_list)
113 {
114 headers_str += std::format("{}: {}\n", header, header_value);
115 }
116 return formatter<string>::format(headers_str, ctx);
117 }
118};
Definition http.hpp:16
Header
Enum of HTTP headers as defined by the standard This enum contains the most commonly used HTTP header...
Definition http_headers.hpp:20
std::vector< std::pair< Header, std::string > > HeadersList
A list of headers A HeadersList is a vector of pairs, where the first element of the pair is a Header...
Definition http_headers.hpp:54
Definition auth.hpp:35
http::Header parseHeaderFromString(const std::string &header_str)
Parse a header string to a Header enum.
Definition http_headers.cpp:5
Definition decentralised_art.hpp:30
auto format(dcn::http::Header header, format_context &ctx) const
Definition http_headers.hpp:69
auto format(dcn::http::HeadersList headers_list, format_context &ctx) const
Definition http_headers.hpp:110