MCPcopy Create free account
hub / github.com/apache/arrow / ParseCookieString

Method ParseCookieString

cpp/src/arrow/flight/sql/server_session_middleware.cc:99–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97};
98
99std::vector<std::pair<std::string, std::string>>
100ServerSessionMiddlewareFactory::ParseCookieString(const std::string_view& s) {
101 const std::string list_sep = "; ";
102 const std::string pair_sep = "=";
103
104 std::vector<std::pair<std::string, std::string>> result;
105
106 size_t cur = 0;
107 while (cur < s.length()) {
108 const size_t end = s.find(list_sep, cur);
109 const bool further_pairs = end != std::string::npos;
110 const size_t len = further_pairs ? end - cur : std::string::npos;
111 const std::string_view tok = s.substr(cur, len);
112 cur = further_pairs ? end + list_sep.length() : s.length();
113
114 const size_t val_pos = tok.find(pair_sep);
115 if (val_pos == std::string::npos) {
116 // The cookie header is somewhat malformed; ignore the key and continue parsing
117 continue;
118 }
119 const std::string_view cookie_name = tok.substr(0, val_pos);
120 std::string_view cookie_value =
121 tok.substr(val_pos + pair_sep.length(), std::string::npos);
122 if (cookie_name.empty()) {
123 continue;
124 }
125 // Strip doublequotes
126 if (cookie_value.length() >= 2 && cookie_value.front() == '"' &&
127 cookie_value.back() == '"') {
128 cookie_value.remove_prefix(1);
129 cookie_value.remove_suffix(1);
130 }
131 result.emplace_back(cookie_name, cookie_value);
132 }
133
134 return result;
135}
136
137Status ServerSessionMiddlewareFactory::StartCall(
138 const CallInfo&, const ServerCallContext& context,

Callers

nothing calls this directly

Calls 6

substrMethod · 0.80
backMethod · 0.80
emplace_backMethod · 0.80
lengthMethod · 0.45
findMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected