XRootD
XrdTpcUtils Class Reference

#include <XrdTpcUtils.hh>

+ Collaboration diagram for XrdTpcUtils:

Static Public Member Functions

static std::string prepareOpenURL (const std::string &reqResource, std::map< std::string, std::string > &reqHeaders, const std::map< std::string, std::string > &hdr2cgimap)
 

Detailed Description

Definition at line 33 of file XrdTpcUtils.hh.

Member Function Documentation

◆ prepareOpenURL()

std::string XrdTpcUtils::prepareOpenURL ( const std::string &  reqResource,
std::map< std::string, std::string > &  reqHeaders,
const std::map< std::string, std::string > &  hdr2cgimap 
)
static

Prepares the file XRootD open URL from the request resource, the xrd-http-query header of the HTTP request and the hdr2cgi map passed in parameter

We first append oss.task=httptpc opaque info. It is therefore guaranteed that after this function is called, at least one opaque info will be part of the full URL. We need to utilize the full URL (including the query string), not just the resource name. The query portion is hidden in the xrd-http-query header; we take this out and combine it with the resource name. We also append the value of the headers configured in tpc.header2cgi to the resource full URL

One special key is authz; this is always stripped out and copied to the Authorization header (which will later be used for XrdSecEntity). The latter copy is only done if the Authorization header is not already present.

Parameters
reqResourcethe HTTP request resource
reqHeadersHTTP request headers that will be modified to contain what is in the authz opaque query if it was provided
hdr2cgimapthe map containing header keys --> XRootD cgi mapping
Returns
the XRootD open URL that will contain at least one opaque parameter (oss.task)

Definition at line 27 of file XrdTpcUtils.cc.

27  {
28  auto iter = XrdOucTUtils::caseInsensitiveFind(reqHeaders,"xrd-http-query");
29  std::stringstream opaque;
30 
31  // https://github.com/xrootd/xrootd/issues/2427 we tell the oss layer that this transfer is a HTTP TPC one
32  opaque << "?" << TPC::TPCHandler::OSS_TASK_OPAQUE;
33 
34  if (iter != reqHeaders.end() && !iter->second.empty()) {
35  std::string token;
36  std::istringstream requestStream(iter->second);
37  auto has_authz_header = XrdOucTUtils::caseInsensitiveFind(reqHeaders,"authorization") != reqHeaders.end();
38  while (std::getline(requestStream, token, '&')) {
39  if (token.empty()) {
40  continue;
41  } else if (!strncmp(token.c_str(), "authz=", 6)) {
42  if (!has_authz_header) {
43  reqHeaders["Authorization"] = token.substr(6);
44  has_authz_header = true;
45  }
46  } else if (!strncmp(token.c_str(), "access_token=", 13) && !has_authz_header) {
47  reqHeaders["Authorization"] = token.substr(13);
48  has_authz_header = true;
49  } else {
50  opaque << "&" << token;
51  }
52  }
53  }
54 
55  // Append CGI coming from the tpc.header2cgi parameter
56  for(auto & hdr2cgi : hdr2cgimap) {
57  auto it = std::find_if(reqHeaders.begin(),reqHeaders.end(),[&hdr2cgi](const auto & elt){
58  return !strcasecmp(elt.first.c_str(),hdr2cgi.first.c_str());
59  });
60  if(it != reqHeaders.end()) {
61  opaque << "&" << hdr2cgi.second << "=" << it->second;
62  }
63  }
64 
65  return reqResource + opaque.str();
66 }
void getline(uchar *buff, int blen)
static constexpr std::string_view OSS_TASK_OPAQUE
Definition: XrdTpcTPC.hh:55
static std::map< std::string, T >::const_iterator caseInsensitiveFind(const std::map< std::string, T > &m, const std::string &lowerCaseSearchKey)
Definition: XrdOucTUtils.hh:79

References XrdOucTUtils::caseInsensitiveFind(), getline(), and TPC::TPCHandler::OSS_TASK_OPAQUE.

+ Here is the call graph for this function:

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