XRootD
Loading...
Searching...
No Matches
XrdHttpCorsHandler Class Reference

#include <XrdHttpCorsHandler.hh>

Inheritance diagram for XrdHttpCorsHandler:
Collaboration diagram for XrdHttpCorsHandler:

Public Member Functions

 XrdHttpCorsHandler ()=default
void addAllowedOrigin (const std::string &origin) override
int Configure (const char *configFN, XrdSysError *errP) override
std::optional< std::string > getCORSAllowOriginHeader (const std::string &origin) override

Detailed Description

Basic CORS plugin implementation

Definition at line 31 of file XrdHttpCorsHandler.hh.

Constructor & Destructor Documentation

◆ XrdHttpCorsHandler()

XrdHttpCorsHandler::XrdHttpCorsHandler ( )
default

Member Function Documentation

◆ addAllowedOrigin()

void XrdHttpCorsHandler::addAllowedOrigin ( const std::string & origin)
overridevirtual

Add trusted origins to the CORS plugin

Parameters
originthe trusted origin to add

Implements XrdHttpCors.

Definition at line 64 of file XrdHttpCorsHandler.cc.

64 {
65 std::string_view origin_sv(origin);
66 XrdOucUtils::trim(origin_sv);
67 if(!origin_sv.empty()) {
68 m_origins.emplace(origin_sv);
69 }
70}
static void trim(std::string &str)

References XrdOucUtils::trim().

Referenced by Configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Configure()

int XrdHttpCorsHandler::Configure ( const char * configFN,
XrdSysError * errP )
overridevirtual

Configure the CORS handler

Parameters
configFNthe configuration file name
errPthe error pointer allowing to log potential errors
Returns
0 if successful, 1 otherwise

Implements XrdHttpCors.

Definition at line 40 of file XrdHttpCorsHandler.cc.

40 {
41 // Get the cors.origin parameters which can be either space-delimited or a repetition of cors.origin
42 XrdOucGatherConf gconf("cors.origin",errP);
43 if(gconf.Gather(configFN,XrdOucGatherConf::only_body) < 0){
44 return 1;
45 }
46 if(gconf.GetLine()) {
47 while(char * val = gconf.GetToken()) {
48 // No need to check for correctness
50 }
51 }
52 return 0;
53}
void addAllowedOrigin(const std::string &origin) override
@ only_body
Only directive bodies as a string blob.

References addAllowedOrigin(), XrdOucGatherConf::Gather(), XrdOucGatherConf::GetLine(), XrdOucGatherConf::GetToken(), and XrdOucGatherConf::only_body.

Here is the call graph for this function:

◆ getCORSAllowOriginHeader()

std::optional< std::string > XrdHttpCorsHandler::getCORSAllowOriginHeader ( const std::string & origin)
overridevirtual

Returns the fully formed Access-Control-Allow-Origin header. If the origin passed in parameter matches one of the previously added origins, it will return "Access-Control-Allow-Origin: matchedOrigin". If the origin passed in parameter does not match any of the previously added origins, then std::nullopt will be returned

Parameters
origin
Returns
either the fully formed Access-Control-Allow-Origin header or nullopt if the origin does not match any added origin

Implements XrdHttpCors.

Definition at line 55 of file XrdHttpCorsHandler.cc.

55 {
56 auto originItor = m_origins.find(origin);
57 if(originItor != m_origins.end()) {
58 return "Access-Control-Allow-Origin: " + origin;
59 }
60 // We did not find any allowed origin, return nullopt
61 return std::nullopt;
62}

The documentation for this class was generated from the following files: