xentara-plugin v2.1
The Xentara Plugin Framework
Loading...
Searching...
No Matches
xentara::security::CorsOriginPattern Class Referencefinal

A pattern used to match HTTP request origins for CORS (Cross-Origin Resource Sharing) More...

#include <xentara/security/CorsOriginPattern.hpp>

Public Member Functions

 CorsOriginPattern ()=default
 Default constructor.
 
template<std::convertible_to< std::string_view > Origin>
 CorsOriginPattern (const Origin &origin)
 Constructor for a pattern that matches a single origin.
 
 CorsOriginPattern (std::string &&origin)
 Move-Constructor for a pattern that matches a single origin.
 
 CorsOriginPattern (std::regex &&pattern)
 Move-Constructor for a pattern that matches a regular expression.
 
 operator bool () const noexcept
 Determines if the pattern is not a default constructed dummy pattern.
 
auto matches (std::string_view origin) const noexcept -> bool
 Checks whether the pattern matches an origin.
 
auto load (utils::json::decoder::Value &value) -> void
 Loads the pattern from a configuration value.
 

Static Public Member Functions

static auto wildcard () -> CorsOriginPattern
 Creates a pattern than matches all valid origins.
 
static auto checkOriginString (std::string_view origin) -> utils::eh::expected< void, std::string_view >
 Checks whether a string is a legal origin.
 

Detailed Description

A pattern used to match HTTP request origins for CORS (Cross-Origin Resource Sharing)

Constructor & Destructor Documentation

◆ CorsOriginPattern() [1/4]

xentara::security::CorsOriginPattern::CorsOriginPattern ( )
default

Default constructor.

This constructor constructs a pattern that matches no origins.

◆ CorsOriginPattern() [2/4]

template<std::convertible_to< std::string_view > Origin>
xentara::security::CorsOriginPattern::CorsOriginPattern ( const Origin &  origin)

Constructor for a pattern that matches a single origin.

Parameters
originThe origin to allow. Must be a valid origin. Valid origins are URLs with no user information and no path, query, or fragment parts. The string “null” is also a valid origin. You can use checkOriginString() to check the origin for validity.
Exceptions
std::invalid_argumentorigin is not a valid origin

◆ CorsOriginPattern() [3/4]

xentara::security::CorsOriginPattern::CorsOriginPattern ( std::string &&  origin)

Move-Constructor for a pattern that matches a single origin.

Parameters
originThe origin to allow. Must be a valid origin. Valid origins are URLs with no user information and no path, query, or fragment parts. The string “null” is also a valid origin. You can use checkOriginString() to check the origin for validity.
Exceptions
std::invalid_argumentorigin is an empty string

◆ CorsOriginPattern() [4/4]

xentara::security::CorsOriginPattern::CorsOriginPattern ( std::regex &&  pattern)

Move-Constructor for a pattern that matches a regular expression.

Member Function Documentation

◆ checkOriginString()

static auto xentara::security::CorsOriginPattern::checkOriginString ( std::string_view  origin) -> utils::eh::expected< void, std::string_view >
static

Checks whether a string is a legal origin.

Parameters
originThe string to check
Returns
A valid expected value, or an (English) error string describing the exact problem, suitable for display to the user.

◆ load()

auto xentara::security::CorsOriginPattern::load ( utils::json::decoder::Value &  value) -> void

Loads the pattern from a configuration value.

Parameters
valueThe value to load the configuration from
Exceptions
std::runtime_errorThe configuration is not valid, or another error occurred.

◆ matches()

auto xentara::security::CorsOriginPattern::matches ( std::string_view  origin) const -> bool
noexcept

Checks whether the pattern matches an origin.

◆ operator bool()

xentara::security::CorsOriginPattern::operator bool ( ) const
explicitnoexcept

Determines if the pattern is not a default constructed dummy pattern.

Returns
Returns true if the pattern is a real, non-default-constructed pattern. Returns false if the pattern is a default constructed object, or true if it is a real pattern that can actually match something.

◆ wildcard()

static auto xentara::security::CorsOriginPattern::wildcard ( ) -> CorsOriginPattern
static

Creates a pattern than matches all valid origins.