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
39
40 Date,
41 Expect,
42
43 Origin
44 };
45
51 using HeadersList = std::vector<std::pair<Header, std::string>>;
52}
53
54namespace dcn::parse
55{
61 http::Header parseHeaderFromString(const std::string & header_str);
62}
63
64template <>
65struct std::formatter<dcn::http::Header> : std::formatter<std::string> {
66 auto format(dcn::http::Header header, format_context& ctx) const {
67 switch(header)
68 {
69 // A
70 case dcn::http::Header::Accept: return formatter<string>::format("Accept", ctx);
71 case dcn::http::Header::AccessControlAllowOrigin: return formatter<string>::format("Access-Control-Allow-Origin", ctx);
72 case dcn::http::Header::AccessControlAllowMethods: return formatter<string>::format("Access-Control-Allow-Methods", ctx);
73 case dcn::http::Header::AccessControlAllowHeaders: return formatter<string>::format("Access-Control-Allow-Headers", ctx);
74 case dcn::http::Header::AccessControlMaxAge: return formatter<string>::format("Access-Control-Max-Age", ctx);
75 case dcn::http::Header::Authorization: return formatter<string>::format("Authorization", ctx);
76
77 // B
78
79 // C
80 case dcn::http::Header::Connection: return formatter<string>::format("Connection", ctx);
81 case dcn::http::Header::ContentEncoding: return formatter<string>::format("Content-Encoding", ctx);
82 case dcn::http::Header::ContentLength: return formatter<string>::format("Content-Length", ctx);
83 case dcn::http::Header::ContentType: return formatter<string>::format("Content-Type", ctx);
84 case dcn::http::Header::CacheControl: return formatter<string>::format("Cache-Control", ctx);
85
86 // D
87 case dcn::http::Header::Date: return formatter<string>::format("Date", ctx);
88
89 // O
90 case dcn::http::Header::Origin: return formatter<string>::format("Origin", ctx);
91
92 // Unknown
93 case dcn::http::Header::Unknown: return formatter<string>::format("Unknown", ctx);
94 }
95 return formatter<string>::format("", ctx);
96 }
97};
98
99template <>
100struct std::formatter<dcn::http::HeadersList> : std::formatter<std::string> {
101 auto format(dcn::http::HeadersList headers_list, format_context& ctx) const {
102 std::string headers_str = "";
103 for(const auto& [header, header_value] : headers_list)
104 {
105 headers_str += std::format("{}: {}\n", header, header_value);
106 }
107 return formatter<string>::format(headers_str, ctx);
108 }
109};
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:51
Definition auth.cpp:4
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:29
auto format(dcn::http::Header header, format_context &ctx) const
Definition http_headers.hpp:66
auto format(dcn::http::HeadersList headers_list, format_context &ctx) const
Definition http_headers.hpp:101