AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::rest::CorsOptions Struct Reference

#include <cors.hpp>

Collaboration diagram for anch::rest::CorsOptions:

Public Attributes

std::vector< std::string > origins = {}
std::vector< std::string > headers = {}
std::vector< std::string > exposedHeaders = {}
bool credentials = false
std::optional< std::chrono::seconds > maxAge = std::nullopt

Detailed Description

Cross-Origin Resource Sharing (CORS) options, set with Api::cors .

Allowed methods are not configured: they are the methods of the routes matching the request path (HEAD with GET , and OPTIONS ).

api.cors({
.origins = {"https://app.example.com"}, // "*" for every origin
.headers = {"Content-Type", "Authorization"}, // "*" for every requested header
.exposedHeaders = {"Location"},
.credentials = true, // not allowed with "*" origin
.maxAge = std::chrono::hours(1)
});
Author
Vincent Lachenal
Since
0.2

Member Data Documentation

◆ credentials

bool anch::rest::CorsOptions::credentials = false

Allow credentials (cookies, Authorization ): Access-Control-Allow-Credentials: true . It can not be used with the "*" origin.

◆ exposedHeaders

std::vector<std::string> anch::rest::CorsOptions::exposedHeaders = {}

Response headers exposed to the browser ( Access-Control-Expose-Headers )

◆ headers

std::vector<std::string> anch::rest::CorsOptions::headers = {}

Allowed request headers (case insensitive), checked on preflight requests. "*" allows every requested header.

◆ maxAge

std::optional<std::chrono::seconds> anch::rest::CorsOptions::maxAge = std::nullopt

Preflight response cache duration ( Access-Control-Max-Age ), not sent when empty

◆ origins

std::vector<std::string> anch::rest::CorsOptions::origins = {}

Allowed origins (scheme://host[:port] ), compared exactly. "*" allows every origin. It can not be empty.


The documentation for this struct was generated from the following file: