Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
CORS.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Framework_WebServer_CORS_h_
5#define _Stroika_Framework_WebServer_CORS_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
10#include "Stroika/Foundation/Containers/Set.h"
11
12/*
13 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
14 */
15
17
18 using namespace Stroika::Foundation;
20 using Containers::Set;
21
22 /**
23 * Options for how the HTTP Server handles CORS (mostly HTTP OPTIONS requests)
24 */
25 struct CORSOptions {
26
27 /**
28 * true or false if credentials allowed on CORS request
29 * \see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
30 */
31 optional<bool> fAllowCredentials;
32
33 /**
34 */
35 static constexpr bool kAllowCredentials_Default{true};
36
37 /**
38 * `Access-Control-Max-Age` header. How long the `Access-Control-Allow-Methods` and `Access-Control-Allow-Headers` headers can be cached.
39 * (rarely set - default good)
40 */
41 optional<unsigned int> fAccessControlMaxAge;
42
43 static constexpr unsigned int kAccessControlMaxAge_Default{24 * 60 * 60};
44
45 /**
46 * This can be {"*"} meaning any origin (default).
47 * Or it can be a list of values present in HTTP Origin Headers (typically just hostname but can be Host:port)
48 */
49 optional<Set<String>> fAllowedOrigins;
50
51 /**
52 */
53 static constexpr string_view kAccessControlWildcard = "*"sv;
54
55 /**
56 * This is the set of headers which will be allowed by Access-Control-Request-Headers OPTIONS requests.
57 * The default - * - kAccessControlWildcard - any - is typically just fine.
58 */
59 optional<Set<String>> fAllowedHeaders;
60
61 /**
62 * @see Characters::ToString ();
63 */
65 };
66 inline const CORSOptions kDefault_CORSOptions{CORSOptions::kAllowCredentials_Default, CORSOptions::kAccessControlMaxAge_Default,
67 Set<String>{CORSOptions::kAccessControlWildcard}, Set<String>{CORSOptions::kAccessControlWildcard}};
68
69}
70
71/*
72 ********************************************************************************
73 ***************************** Implementation Details ***************************
74 ********************************************************************************
75 */
76#include "CORS.inl"
77
78#endif /*_Stroika_Framework_WebServer_CORS_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
Definition Set.h:105
Characters::String ToString() const
Definition CORS.cpp:22
optional< unsigned int > fAccessControlMaxAge
Definition CORS.h:41
optional< Set< String > > fAllowedOrigins
Definition CORS.h:49
optional< Set< String > > fAllowedHeaders
Definition CORS.h:59