AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
headers.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-rest-common-export.hpp"
23
24#include <map>
25#include <optional>
26#include <string>
27#include <string_view>
28#include <vector>
29
30namespace anch::rest {
31
39 struct ANCH_REST_COMMON_EXPORT CaseInsensitiveLess {
41 using is_transparent = void;
42
51 bool operator()(std::string_view left, std::string_view right) const noexcept;
52 };
53
62 class ANCH_REST_COMMON_EXPORT Headers {
63
64 public:
66 using Map = std::map<std::string, std::vector<std::string>, anch::rest::CaseInsensitiveLess>;
67
68 // Attributes +
69 private:
71 Map _values;
72 // Attributes -
73
74 // Methods +
75 public:
82 void add(std::string_view name, std::string_view value);
83
90 void set(std::string_view name, std::string_view value);
91
99 bool remove(std::string_view name);
100
108 bool has(std::string_view name) const;
109
117 std::optional<std::string_view> get(std::string_view name) const;
118
126 const std::vector<std::string>& getAll(std::string_view name) const;
127
135 std::optional<std::string> format(std::string_view name) const;
136
142 std::size_t size() const noexcept;
143
149 bool empty() const noexcept;
150
156 Map::const_iterator begin() const noexcept;
157
163 Map::const_iterator end() const noexcept;
164
172 bool operator==(const Headers& other) const = default;
173 // Methods -
174
175 };
176
177}
178
179namespace anch::rest::header {
180
182 inline constexpr std::string_view ACCEPT = "Accept";
184 inline constexpr std::string_view ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
186 inline constexpr std::string_view ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers";
188 inline constexpr std::string_view ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods";
190 inline constexpr std::string_view ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
192 inline constexpr std::string_view ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
194 inline constexpr std::string_view ACCESS_CONTROL_MAX_AGE = "Access-Control-Max-Age";
196 inline constexpr std::string_view ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers";
198 inline constexpr std::string_view ACCESS_CONTROL_REQUEST_METHOD = "Access-Control-Request-Method";
200 inline constexpr std::string_view ALLOW = "Allow";
202 inline constexpr std::string_view AUTHORIZATION = "Authorization";
204 inline constexpr std::string_view CACHE_CONTROL = "Cache-Control";
206 inline constexpr std::string_view CONTENT_DISPOSITION = "Content-Disposition";
208 inline constexpr std::string_view CONTENT_LENGTH = "Content-Length";
210 inline constexpr std::string_view CONTENT_TYPE = "Content-Type";
212 inline constexpr std::string_view ETAG = "ETag";
214 inline constexpr std::string_view LOCATION = "Location";
216 inline constexpr std::string_view ORIGIN = "Origin";
218 inline constexpr std::string_view USER_AGENT = "User-Agent";
220 inline constexpr std::string_view VARY = "Vary";
222 inline constexpr std::string_view WWW_AUTHENTICATE = "WWW-Authenticate";
224 inline constexpr std::string_view X_CORRELATION_ID = "X-Correlation-ID";
226 inline constexpr std::string_view X_REQUEST_ID = "X-Request-ID";
227
228}
Definition headers.hpp:62
bool has(std::string_view name) const
std::map< std::string, std::vector< std::string >, anch::rest::CaseInsensitiveLess > Map
Definition headers.hpp:66
const std::vector< std::string > & getAll(std::string_view name) const
void set(std::string_view name, std::string_view value)
bool remove(std::string_view name)
std::optional< std::string > format(std::string_view name) const
Map::const_iterator begin() const noexcept
Map::const_iterator end() const noexcept
std::optional< std::string_view > get(std::string_view name) const
void add(std::string_view name, std::string_view value)
std::size_t size() const noexcept
bool empty() const noexcept
Common HTTP header names.
Definition headers.hpp:179
constexpr std::string_view ALLOW
Definition headers.hpp:200
constexpr std::string_view ACCESS_CONTROL_REQUEST_HEADERS
Definition headers.hpp:196
constexpr std::string_view X_CORRELATION_ID
Definition headers.hpp:224
constexpr std::string_view ACCESS_CONTROL_ALLOW_CREDENTIALS
Definition headers.hpp:184
constexpr std::string_view USER_AGENT
Definition headers.hpp:218
constexpr std::string_view CACHE_CONTROL
Definition headers.hpp:204
constexpr std::string_view ACCESS_CONTROL_ALLOW_ORIGIN
Definition headers.hpp:190
constexpr std::string_view CONTENT_DISPOSITION
Definition headers.hpp:206
constexpr std::string_view ORIGIN
Definition headers.hpp:216
constexpr std::string_view WWW_AUTHENTICATE
Definition headers.hpp:222
constexpr std::string_view ACCESS_CONTROL_EXPOSE_HEADERS
Definition headers.hpp:192
constexpr std::string_view VARY
Definition headers.hpp:220
constexpr std::string_view ACCESS_CONTROL_ALLOW_HEADERS
Definition headers.hpp:186
constexpr std::string_view ETAG
Definition headers.hpp:212
constexpr std::string_view ACCESS_CONTROL_ALLOW_METHODS
Definition headers.hpp:188
constexpr std::string_view CONTENT_LENGTH
Definition headers.hpp:208
constexpr std::string_view ACCESS_CONTROL_MAX_AGE
Definition headers.hpp:194
constexpr std::string_view LOCATION
Definition headers.hpp:214
constexpr std::string_view CONTENT_TYPE
Definition headers.hpp:210
constexpr std::string_view ACCEPT
Definition headers.hpp:182
constexpr std::string_view X_REQUEST_ID
Definition headers.hpp:226
constexpr std::string_view AUTHORIZATION
Definition headers.hpp:202
constexpr std::string_view ACCESS_CONTROL_REQUEST_METHOD
Definition headers.hpp:198
AnCH REST library namespace.
Definition auth.hpp:29
AnCH framework base namespace.
Definition app.hpp:30
Definition headers.hpp:39
void is_transparent
Definition headers.hpp:41
bool operator()(std::string_view left, std::string_view right) const noexcept