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

#include <XrdHttpHeaderUtils.hh>

Collaboration diagram for XrdHttpHeaderUtils:

Static Public Member Functions

static void parseReprDigest (const std::string &value, std::map< std::string, std::string > &output)
static void parseWantReprDigest (const std::string &value, std::map< std::string, uint8_t > &output)

Detailed Description

Definition at line 30 of file XrdHttpHeaderUtils.hh.

Member Function Documentation

◆ parseReprDigest()

void XrdHttpHeaderUtils::parseReprDigest ( const std::string & value,
std::map< std::string, std::string > & output )
static

Parses the 'Repr-Digest' header value received from the client Syntax: "Repr-Digest: adler=:base64EncodedValue:, crc32=:base64EncodedValue:

Parameters
valuecontains the value of the header Repr-Digest
outputthe map containing the digests and their associated base64 encoded values

Definition at line 31 of file XrdHttpHeaderUtils.cc.

31 {
32 // Expected format per entry: <cksumType>=:<digestValue>:
33 std::vector<std::string> digestNameValuePairs;
34 XrdOucTUtils::splitString(digestNameValuePairs, value, ",");
35
36 for (const auto &digestNameValue : digestNameValuePairs) {
37 std::string_view digestNameValueSV {digestNameValue};
38 auto equalPos = digestNameValueSV.find('=');
39 if (equalPos == std::string_view::npos || equalPos >= digestNameValueSV.size() - 1)
40 continue;
41
42 std::string_view cksumTypeSV = digestNameValueSV.substr(0, equalPos);
43 XrdOucUtils::trim(cksumTypeSV);
44 if (cksumTypeSV.empty())
45 continue;
46
47 std::string_view cksumValueInSV = digestNameValueSV.substr(equalPos + 1);
48 size_t beginCksumPos = cksumValueInSV.find(':');
49 size_t endCksumPos = cksumValueInSV.rfind(':');
50
51 // Check that the string starts with ':' and contains two distinct colons
52 if (beginCksumPos == 0 && endCksumPos > beginCksumPos + 1 && endCksumPos < cksumValueInSV.size()) {
53 std::string_view cksumValue = cksumValueInSV.substr(beginCksumPos + 1, endCksumPos - beginCksumPos - 1);
54 XrdOucUtils::trim(cksumValue);
55 if (!cksumValue.empty()) {
56 //What we get as checksum value is a base64-encoded hexadecimal bytes
57 //Let's decode that.
58 std::string chksumDecoded;
59 base64DecodeHex(std::string(cksumValue), chksumDecoded);
60 std::string cksumTypeLC {cksumTypeSV};
61 std::transform(cksumTypeLC.begin(), cksumTypeLC.end(), cksumTypeLC.begin(), ::tolower);
62 output[cksumTypeLC] = chksumDecoded;
63 }
64 }
65 // Malformed entries are silently ignored
66 }
67}
void base64DecodeHex(const std::string &base64, std::string &hexOutput)
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
static void trim(std::string &str)

References base64DecodeHex(), XrdOucTUtils::splitString(), and XrdOucUtils::trim().

Referenced by XrdHttpReq::parseLine().

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

◆ parseWantReprDigest()

void XrdHttpHeaderUtils::parseWantReprDigest ( const std::string & value,
std::map< std::string, uint8_t > & output )
static

Parses 'Want-Repr-Digest' header value received from the client Syntax: "Want-Repr-Digest: adler=1, crc32=2, sha-256=9 The values are integers representing the preference, comprised between 0 and 9.

Parameters
valuecontains the value of the header Want-Repr-Digest
outputthe map containing the lower-cased digest name and the associated preference

Definition at line 69 of file XrdHttpHeaderUtils.cc.

69 {
70 size_t pos = 0;
71 std::string_view value_sv {value};
72 while(pos <= value_sv.size()) {
73 // find comma
74 size_t comma = value.find(',',pos);
75 // extract item, no comma means the item is the full string
76 std::string_view item = (comma == std::string_view::npos) ? value_sv.substr(pos) : value_sv.substr(pos, comma - pos);
77 // move current cursor to 'comma + 1' or after the string end
78 pos = (comma == std::string_view::npos) ? value.size() + 1 : comma + 1;
79 // trim the item
81 if(item.empty()) continue;
82
83 size_t eq = item.find('=');
84 // If no '=' sign, we discard this entry as it is malformed
85 if(eq == std::string_view::npos) continue;
86 // We found the equal sign on the item
87 std::string_view digestName {item.substr(0, eq)};
88 XrdOucUtils::trim(digestName);
89 std::string_view preference {item.substr(eq+1)};
90 XrdOucUtils::trim(preference);
91
92 std::string key_lower {digestName};
93 std::transform(key_lower.begin(),key_lower.end(),key_lower.begin(),::tolower);
94
95 try {
96 uint8_t preference_us = XrdOucUtils::touint8_t(preference);
97 // Max allowed value for Repr-Digest is 10
98 preference_us = std::min(preference_us,(uint8_t)10);
99 output[key_lower] = preference_us;
100 } catch (...) {
101 // discard invalid values
102 }
103 }
104}
static uint8_t touint8_t(const std::string_view sv)

References XrdOucUtils::touint8_t(), and XrdOucUtils::trim().

Referenced by XrdHttpReq::parseLine().

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

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