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
AccessControlMaxAge
,
30
31
Authorization
,
32
33
Connection
,
34
ContentEncoding
,
35
ContentLength
,
36
ContentType
,
37
38
CacheControl
,
39
40
Date
,
41
Expect
,
42
43
Origin
44
};
45
51
using
HeadersList
= std::vector<std::pair<Header, std::string>>;
52
}
53
54
namespace
dcn::parse
55
{
61
http::Header
parseHeaderFromString
(
const
std::string & header_str);
62
}
63
64
template
<>
65
struct
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
99
template
<>
100
struct
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
};
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::AccessControlMaxAge
@ AccessControlMaxAge
dcn::http::Header::AccessControlAllowMethods
@ AccessControlAllowMethods
dcn::http::Header::Origin
@ Origin
dcn::http::Header::Date
@ Date
dcn::http::Header::Expect
@ Expect
dcn::http::Header::Unknown
@ Unknown
dcn::http::Header::CacheControl
@ CacheControl
dcn::http::Header::ContentEncoding
@ ContentEncoding
dcn::http::Header::Authorization
@ Authorization
dcn::http::Header::ContentType
@ ContentType
dcn::http::Header::AccessControlAllowOrigin
@ AccessControlAllowOrigin
dcn::http::Header::Connection
@ Connection
dcn::http::Header::Accept
@ Accept
dcn::http::Header::AccessControlAllowHeaders
@ AccessControlAllowHeaders
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:51
dcn::parse
Definition
auth.cpp:4
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:29
std::formatter< dcn::http::Header >::format
auto format(dcn::http::Header header, format_context &ctx) const
Definition
http_headers.hpp:66
std::formatter< dcn::http::HeadersList >::format
auto format(dcn::http::HeadersList headers_list, format_context &ctx) const
Definition
http_headers.hpp:101
utils.hpp
src
http
include
http_headers.hpp
Generated by
1.9.8