XRootD
Loading...
Searching...
No Matches
XrdClHttp::VerbsCache Class Reference

#include <XrdClHttpOptionsCache.hh>

Collaboration diagram for XrdClHttp::VerbsCache:

Classes

class  HttpVerbs

Public Types

enum class  HttpVerb {
  kUnset = 0 ,
  kUnknown = 1 ,
  kPROPFIND = 2
}

Public Member Functions

void Expire (std::chrono::steady_clock::time_point now)
HttpVerbs Get (const std::string &url, const std::chrono::steady_clock::time_point &now=std::chrono::steady_clock::now()) const
uint64_t GetCacheHits () const
uint64_t GetCacheMisses () const
void Put (const std::string &url, const HttpVerbs &verbs, const std::chrono::steady_clock::time_point &now=std::chrono::steady_clock::now()) const

Static Public Member Functions

static std::string_view GetUrlKey (const std::string &url, std::string &modified_url)
static const std::string GetVerbString (HttpVerb ctype)
static VerbsCache & Instance ()

Detailed Description

Definition at line 37 of file XrdClHttpOptionsCache.hh.

Member Enumeration Documentation

◆ HttpVerb

Enumerator
kUnset 
kUnknown 
kPROPFIND 

Definition at line 41 of file XrdClHttpOptionsCache.hh.

41 {
42 kUnset = 0, // Indicates that we haven't yet probed for the HTTP verb support.
43 kUnknown = 1, // Indicates we probed for support but the result was indeterminate (not provided by the server, network error)
44 kPROPFIND = 2, // Server claims to support PROPFIND
45 };

Member Function Documentation

◆ Expire()

void XrdClHttp::VerbsCache::Expire ( std::chrono::steady_clock::time_point now)

Definition at line 67 of file XrdClHttpOptionsCache.cc.

68{
69 std::unique_lock lock(m_mutex);
70 for (auto iter = m_verbs_map.begin(); iter != m_verbs_map.end();) {
71 if (iter->second.m_expiry < now) {
72 iter = m_verbs_map.erase(iter);
73 } else {
74 ++iter;
75 }
76 }
77}

◆ Get()

HttpVerbs XrdClHttp::VerbsCache::Get ( const std::string & url,
const std::chrono::steady_clock::time_point & now = std::chrono::steady_clock::now() ) const
inline

Definition at line 95 of file XrdClHttpOptionsCache.hh.

95 {
96 std::string modified_url;
97 auto key = GetUrlKey(url, modified_url);
98
99 const std::shared_lock sentry(m_mutex);
100#if __cplusplus >= 202002L
101 auto iter = m_verbs_map.find(key);
102#else
103 auto iter = m_verbs_map.find(std::string(key));
104#endif
105 if (iter == m_verbs_map.end()) {
106 m_cache_miss++;
107 return HttpVerbs{};
108 }
109 if (iter->second.m_expiry < now) {
110 m_cache_miss++;
111 return HttpVerbs{};
112 }
113 m_cache_hit++;
114 return iter->second.m_verbs;
115 }
static std::string_view GetUrlKey(const std::string &url, std::string &modified_url)

References GetUrlKey().

Here is the call graph for this function:

◆ GetCacheHits()

uint64_t XrdClHttp::VerbsCache::GetCacheHits ( ) const
inline

Definition at line 140 of file XrdClHttpOptionsCache.hh.

140{return m_cache_hit;}

◆ GetCacheMisses()

uint64_t XrdClHttp::VerbsCache::GetCacheMisses ( ) const
inline

Definition at line 141 of file XrdClHttpOptionsCache.hh.

141{return m_cache_miss;}

◆ GetUrlKey()

std::string_view XrdClHttp::VerbsCache::GetUrlKey ( const std::string & url,
std::string & modified_url )
inlinestatic

Definition at line 120 of file XrdClHttpOptionsCache.hh.

120 {
121 auto authority_loc = url.find("://");
122 if (authority_loc == std::string::npos) {
123 return std::string_view();
124 }
125 auto path_loc = url.find('/', authority_loc + 3);
126 if (path_loc == std::string::npos) {
127 path_loc = url.length();
128 }
129
130 std::string_view url_view{url};
131 auto host_loc = url_view.substr(authority_loc + 3, path_loc - authority_loc - 3).find('@');
132 if (host_loc == std::string::npos) {
133 return url_view.substr(0, path_loc);
134 }
135 host_loc += authority_loc + 3;
136 modified_url = url.substr(0, authority_loc + 3) + std::string(url_view.substr(host_loc + 1, path_loc - host_loc - 1));
137 return modified_url;
138 }

Referenced by Get(), Put(), and XrdClHttp::CurlWorker::Run().

Here is the caller graph for this function:

◆ GetVerbString()

const std::string XrdClHttp::VerbsCache::GetVerbString ( HttpVerb ctype)
inlinestatic

Definition at line 61 of file XrdClHttpOptionsCache.hh.

61 {
62 switch (ctype) {
64 return "(unset)";
66 return "(unknown)";
68 return "PROPFIND";
69 }
70 }

References kPROPFIND, kUnknown, and kUnset.

◆ Instance()

XrdClHttp::VerbsCache & XrdClHttp::VerbsCache::Instance ( )
static

Definition at line 37 of file XrdClHttpOptionsCache.cc.

37 {
38 std::unique_lock lk(m_shutdown_lock);
39 if (!m_shutdown_requested) {
40 std::call_once(m_expiry_launch, [] {
41 std::thread t(VerbsCache::ExpireThread);
42 m_expire_tid = std::move(t);
43 });
44 }
45 return g_cache;
46}

Referenced by XrdClHttp::CurlOptionsOp::Fail(), XrdClHttp::CurlStatOp::OptionsDone(), XrdClHttp::CurlStatOp::Redirect(), XrdClHttp::CurlStatOp::RequiresOptions(), XrdClHttp::CurlStatOp::Setup(), and XrdClHttp::CurlOptionsOp::Success().

Here is the caller graph for this function:

◆ Put()

void XrdClHttp::VerbsCache::Put ( const std::string & url,
const HttpVerbs & verbs,
const std::chrono::steady_clock::time_point & now = std::chrono::steady_clock::now() ) const
inline

Definition at line 72 of file XrdClHttpOptionsCache.hh.

72 {
73 std::string modified_url;
74 auto key = GetUrlKey(url, modified_url);
75
76 const std::unique_lock sentry(m_mutex);
77
78 auto isKnown = !verbs.IsSet(HttpVerb::kUnknown);
79 auto lifetime = isKnown ? g_expiry_duration : g_negative_expiry_duration;
80
81// C++20 can elide the allocation for the string_view
82#if __cplusplus >= 202002L
83 auto iter = m_verbs_map.find(key);
84#else
85 auto iter = m_verbs_map.find(std::string(key));
86#endif
87 if (iter == m_verbs_map.end()) {
88 m_verbs_map.emplace(key, VerbEntry{now + lifetime, verbs});
89 } else if (isKnown || iter->second.m_verbs.IsSet(HttpVerb::kUnknown)) {
90 // Previous entry didn't know the verbs, but now we do
91 iter->second = {now + lifetime, verbs};
92 }
93 }

References GetUrlKey(), XrdClHttp::VerbsCache::HttpVerbs::IsSet(), and kUnknown.

Here is the call graph for this function:

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