MCPcopy Create free account
hub / github.com/CesiumGS/cesium-native / parseFromResponseHeaders

Method parseFromResponseHeaders

CesiumAsync/src/ResponseCacheControl.cpp:54–130  ·  view source on GitHub ↗

static*/

Source from the content-addressed store, hash-verified

52 _staleWhileRevalidate{staleWhileRevalidate} {}
53
54/*static*/ std::optional<ResponseCacheControl>
55ResponseCacheControl::parseFromResponseHeaders(const HttpHeaders& headers) {
56 std::map<std::string, std::string, CaseInsensitiveCompare>::const_iterator
57 cacheControlIter = headers.find("Cache-Control");
58 if (cacheControlIter == headers.end()) {
59 return std::nullopt;
60 }
61
62 const std::string& headerValue = cacheControlIter->second;
63 std::map<std::string, std::string, CaseInsensitiveCompare>
64 parameterizedDirectives;
65 std::set<std::string, CaseInsensitiveCompare> directives;
66 size_t last = 0;
67 size_t next = 0;
68 while ((next = headerValue.find(',', last)) != std::string::npos) {
69 std::string directive = trimSpace(headerValue.substr(last, next - last));
70 const size_t equalSize = directive.find('=');
71 if (equalSize != std::string::npos) {
72 parameterizedDirectives.insert(
73 {trimSpace(directive.substr(0, equalSize)),
74 trimSpace(directive.substr(equalSize + 1))});
75 } else {
76 directives.insert(directive);
77 }
78
79 last = next + 1;
80 }
81
82 std::string directive = trimSpace(headerValue.substr(last));
83 const size_t equalSize = directive.find('=');
84 if (equalSize != std::string::npos) {
85 parameterizedDirectives.insert(
86 {trimSpace(directive.substr(0, equalSize)),
87 trimSpace(directive.substr(equalSize + 1))});
88 } else {
89 directives.insert(directive);
90 }
91
92 bool mustRevalidate = directives.find("must-revalidate") != directives.end();
93 bool noCache = directives.find("no-cache") != directives.end();
94 bool noStore = directives.find("no-store") != directives.end();
95 bool noTransform = directives.find("no-transform") != directives.end();
96 bool accessControlPublic = directives.find("public") != directives.end();
97 bool accessControlPrivate = directives.find("private") != directives.end();
98 bool proxyRevalidate =
99 directives.find("proxy-revalidate") != directives.end();
100
101 std::map<std::string, std::string, CaseInsensitiveCompare>::const_iterator
102 mapIter;
103
104 std::optional<int> maxAge;
105 mapIter = parameterizedDirectives.find("max-age");
106 if (mapIter != parameterizedDirectives.end())
107 maxAge = std::stoi(mapIter->second);
108
109 std::optional<int> sharedMaxAge;
110 mapIter = parameterizedDirectives.find("s-maxage");
111 if (mapIter != parameterizedDirectives.end())

Callers

nothing calls this directly

Calls 3

trimSpaceFunction · 0.85
endMethod · 0.45

Tested by

no test coverage detected