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 <format>
4#include <string>
5#include <vector>
6
7namespace dcn::http
8{
14 enum class Header
15 {
16 // Unknown, specially reserved
17 Unknown = 0,
18
19 Accept,
24
29
30 Cookie,
31 Date,
32 Expect,
33
35 };
36
42 using HeadersList = std::vector<std::pair<Header, std::string>>;
43}
44
45namespace dcn::parse
46{
53}
54
55template <>
56struct std::formatter<dcn::http::Header> : std::formatter<std::string> {
57 auto format(dcn::http::Header header, format_context& ctx) const {
58 switch(header)
59 {
60 // A
61 case dcn::http::Header::Accept: return formatter<string>::format("Accept", ctx);
62 case dcn::http::Header::AccessControlAllowOrigin: return formatter<string>::format("Access-Control-Allow-Origin", ctx);
63 case dcn::http::Header::AccessControlAllowMethods: return formatter<string>::format("Access-Control-Allow-Methods", ctx);
64 case dcn::http::Header::AccessControlAllowHeaders: return formatter<string>::format("Access-Control-Allow-Headers", ctx);
65 case dcn::http::Header::Authorization: return formatter<string>::format("Authorization", ctx);
66
67 // B
68
69 // C
70 case dcn::http::Header::Connection: return formatter<string>::format("Connection", ctx);
71 case dcn::http::Header::ContentEncoding: return formatter<string>::format("Content-Encoding", ctx);
72 case dcn::http::Header::ContentLength: return formatter<string>::format("Content-Length", ctx);
73 case dcn::http::Header::ContentType: return formatter<string>::format("Content-Type", ctx);
74 case dcn::http::Header::Cookie: return formatter<string>::format("Cookie", ctx);
75
76 // D
77 case dcn::http::Header::Date: return formatter<string>::format("Date", ctx);
78
79 // S
80 case dcn::http::Header::SetCookie: return formatter<string>::format("Set-Cookie", ctx);
81
82
83 // Unknown
84 case dcn::http::Header::Unknown: return formatter<string>::format("Unknown", ctx);
85 }
86 return formatter<string>::format("", ctx);
87 }
88};
89
90template <>
91struct std::formatter<dcn::http::HeadersList> : std::formatter<std::string> {
92 auto format(dcn::http::HeadersList headers_list, format_context& ctx) const {
93 std::string headers_str = "";
94 for(const auto& [header, header_value] : headers_list)
95 {
96 headers_str += std::format("{}: {}\n", header, header_value);
97 }
98 return formatter<string>::format(headers_str, ctx);
99 }
100};
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:15
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:42
Definition auth.hpp:34
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:57
auto format(dcn::http::HeadersList headers_list, format_context &ctx) const
Definition http_headers.hpp:92