MCPcopy Create free account
hub / github.com/apache/trafficserver / _getIncludeData

Method _getIncludeData

plugins/esi/lib/EsiProcessor.cc:209–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207}
208
209bool
210EsiProcessor::_getIncludeData(const DocNode &node, const char **content_ptr /* = 0 */, int *content_len_ptr /* = 0 */)
211{
212 if (node.type == DocNode::TYPE_INCLUDE) {
213 const Attribute &url = node.attr_list.front();
214
215 if (url.value_len == 0) { // allow empty url
216 if (content_ptr && content_len_ptr) {
217 *content_ptr = nullptr;
218 *content_len_ptr = 0;
219 return true;
220 } else {
221 return false;
222 }
223 }
224
225 string raw_url(url.value, url.value_len);
226 StringHash::iterator iter = _include_urls.find(raw_url);
227 if (iter == _include_urls.end()) {
228 TSError("[%s] Data not requested for URL [%.*s]; no data to include", __FUNCTION__, url.value_len, url.value);
229 return false;
230 }
231 const string &processed_url = iter->second;
232 bool result;
233 if (content_ptr && content_len_ptr) {
234 result = _fetcher.getContent(processed_url, *content_ptr, *content_len_ptr);
235 } else {
236 result = (_fetcher.getRequestStatus(processed_url) == STATUS_DATA_AVAILABLE);
237 }
238 if (!result) {
239 TSError("[%s] Couldn't get content for URL [%.*s]", __FUNCTION__, int(processed_url.size()), processed_url.data());
240 Stats::increment(Stats::N_INCLUDE_ERRS);
241 return false;
242 }
243 DBG("[%s] Got content successfully for URL [%.*s]", __FUNCTION__, int(processed_url.size()), processed_url.data());
244 return true;
245 } else if (node.type == DocNode::TYPE_SPECIAL_INCLUDE) {
246 int include_data_id = 0;
247 SpecialIncludeHandler *handler = nullptr;
248 for (AttributeList::const_iterator attr_iter = node.attr_list.begin(); attr_iter != node.attr_list.end(); ++attr_iter) {
249 if (attr_iter->name == INCLUDE_DATA_ID_ATTR) {
250 include_data_id = attr_iter->value_len;
251 handler = reinterpret_cast<SpecialIncludeHandler *>(const_cast<char *>(attr_iter->value));
252 break;
253 }
254 }
255 if (include_data_id == 0 || handler == nullptr) {
256 TSError("[%s] Fail to find the special include data id attribute", __FUNCTION__);
257 Stats::increment(Stats::N_SPCL_INCLUDE_ERRS);
258 return false;
259 }
260 bool result;
261 if (content_ptr && content_len_ptr) {
262 result = handler->getData(include_data_id, *content_ptr, *content_len_ptr);
263 } else {
264 result = (handler->getIncludeStatus(include_data_id) == STATUS_DATA_AVAILABLE);
265 }
266 if (!result) {

Callers

nothing calls this directly

Calls 11

incrementFunction · 0.85
getIncludeStatusMethod · 0.80
TSErrorFunction · 0.50
findMethod · 0.45
endMethod · 0.45
getContentMethod · 0.45
getRequestStatusMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
beginMethod · 0.45
getDataMethod · 0.45

Tested by

no test coverage detected