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
12
namespace
dcn::http
13
{
19
enum class
Header
20
{
21
// Unknown, specially reserved
22
Unknown
= 0,
23
24
Accept
,
25
26
AccessControlAllowOrigin
,
27
AccessControlAllowMethods
,
28
AccessControlAllowHeaders
,
29
AccessControlAllowCredentials
,
30
31
Authorization
,
32
33
Connection
,
34
ContentEncoding
,
35
ContentLength
,
36
ContentType
,
37
38
Cookie
,
39
Date
,
40
Expect
,
41
42
Origin
,
43
44
SetCookie
,
45
46
XRefreshToken
47
};
48
54
using
HeadersList
= std::vector<std::pair<Header, std::string>>;
55
}
56
57
namespace
dcn::parse
58
{
64
http::Header
parseHeaderFromString
(
const
std::string &
header_str
);
65
}
66
67
template
<>
68
struct
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
108
template
<>
109
struct
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
};
dcn::http
Definition
http.hpp:16
dcn::http::Code::Unknown
@ Unknown
dcn::http::Header
Header
Enum of HTTP headers as defined by the standard This enum contains the most commonly used HTTP header...
Definition
http_headers.hpp:20
dcn::http::Header::ContentLength
@ ContentLength
dcn::http::Header::SetCookie
@ SetCookie
dcn::http::Header::AccessControlAllowMethods
@ AccessControlAllowMethods
dcn::http::Header::Origin
@ Origin
dcn::http::Header::Date
@ Date
dcn::http::Header::Cookie
@ Cookie
dcn::http::Header::Expect
@ Expect
dcn::http::Header::Unknown
@ Unknown
dcn::http::Header::ContentEncoding
@ ContentEncoding
dcn::http::Header::Authorization
@ Authorization
dcn::http::Header::ContentType
@ ContentType
dcn::http::Header::AccessControlAllowOrigin
@ AccessControlAllowOrigin
dcn::http::Header::XRefreshToken
@ XRefreshToken
dcn::http::Header::Connection
@ Connection
dcn::http::Header::Accept
@ Accept
dcn::http::Header::AccessControlAllowHeaders
@ AccessControlAllowHeaders
dcn::http::Header::AccessControlAllowCredentials
@ AccessControlAllowCredentials
dcn::http::HeadersList
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
dcn::parse
Definition
auth.hpp:35
dcn::parse::parseHeaderFromString
http::Header parseHeaderFromString(const std::string &header_str)
Parse a header string to a Header enum.
Definition
http_headers.cpp:5
dcn
Definition
decentralised_art.hpp:30
dcn::RouteArgRequirement::optional
@ optional
std::formatter< dcn::http::Header >::format
auto format(dcn::http::Header header, format_context &ctx) const
Definition
http_headers.hpp:69
std::formatter< dcn::http::HeadersList >::format
auto format(dcn::http::HeadersList headers_list, format_context &ctx) const
Definition
http_headers.hpp:110
utils.hpp
src
http
include
http_headers.hpp
Generated by
1.9.8