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

Function getCmcdNor

plugins/prefetch/plugin.cc:368–422  ·  view source on GitHub ↗

* @brief Look for and return the nor field of any Cmcd-Request header * * @param txnp HTTP transaction structure * @param buffer request TSMBuffer * @param hdrloc request TSMLoc * @return unquoted relative cmcd path from the nor field * * If the 'nrr' field is encountered the 'nor' field will be ignored. * * sample header: * Cmcd-Request: mtp=103600,bl=153500,nor="14_176.mp4a" */

Source from the content-addressed store, hash-verified

366 * Cmcd-Request: mtp=103600,bl=153500,nor="14_176.mp4a"
367 */
368static String
369getCmcdNor(const TSMBuffer buffer, const TSMLoc hdrloc)
370{
371 String relpath;
372 bool hasnrr = false; // don't prefetch if range request
373
374 const TSMLoc cmcdloc = TSMimeHdrFieldFind(buffer, hdrloc, CmcdHeader.data(), CmcdHeader.length());
375 if (TS_NULL_MLOC != cmcdloc) {
376 // iterate through the fields
377 const int cnt = TSMimeHdrFieldValuesCount(buffer, hdrloc, cmcdloc);
378 for (int ind = 0; ind < cnt; ++ind) {
379 int flen = 0;
380 const char *const fval = TSMimeHdrFieldValueStringGet(buffer, hdrloc, cmcdloc, ind, &flen);
381
382 StringView fv(fval, flen);
383 PrefetchDebug("cmcd-request field: '%.*s'", (int)fv.length(), fv.data());
384 if (0 == fv.compare(0, CmcdNrrFieldPrefix.length(), CmcdNrrFieldPrefix)) {
385 PrefetchDebug("cmcd-request nrr field encountered, skipping prefetch!");
386 hasnrr = true;
387 break;
388 }
389
390 if (0 == fv.compare(0, CmcdNorFieldPrefix.length(), CmcdNorFieldPrefix)) {
391 fv.remove_prefix(CmcdNorFieldPrefix.length());
392 if (fv.front() == '"') {
393 fv.remove_prefix(1);
394 }
395 if (fv.back() == '"') {
396 fv.remove_suffix(1);
397 }
398
399 PrefetchDebug("Extracted nor field: '%.*s'", (int)fv.length(), fv.data());
400
401 // Undo any percent encoding
402 char buf[8192];
403 size_t blen = sizeof(buf);
404 if (TS_SUCCESS == TSStringPercentDecode(fv.data(), fv.length(), buf, blen, &blen)) {
405 relpath.assign(buf, blen);
406 } else {
407 PrefetchDebug("Error percent decoding nor field: '%.*s'", (int)fv.length(), fv.data());
408 }
409 }
410 }
411 TSHandleMLocRelease(buffer, hdrloc, cmcdloc);
412 } else {
413 PrefetchDebug("No Cmcd-Request header found");
414 }
415
416 // don't prefetch if range request
417 if (hasnrr) {
418 relpath.clear();
419 }
420
421 return relpath;
422}
423
424/**
425 * @brief short-cut to set the response .

Callers 1

contHandleFetchFunction · 0.85

Calls 12

TSMimeHdrFieldFindFunction · 0.85
TSStringPercentDecodeFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
dataMethod · 0.45
lengthMethod · 0.45
compareMethod · 0.45
remove_prefixMethod · 0.45
remove_suffixMethod · 0.45
assignMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected