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

Function contHandleFetch

plugins/prefetch/plugin.cc:494–745  ·  view source on GitHub ↗

* @brief Callback function that handles necessary foreground / background fetch operations. * * @param contp continuation associated with this function. * @param event corresponding event triggered at different hooks. * @param edata HTTP transaction structures. * @return always 0 */

Source from the content-addressed store, hash-verified

492 * @return always 0
493 */
494int
495contHandleFetch(const TSCont contp, TSEvent event, void *edata)
496{
497 PrefetchTxnData *data = static_cast<PrefetchTxnData *>(TSContDataGet(contp));
498 TSHttpTxn txnp = static_cast<TSHttpTxn>(edata);
499 PrefetchConfig &config = data->_inst->_config;
500 BgFetchState *state = data->_inst->_state;
501 TSMBuffer reqBuffer = nullptr;
502 TSMLoc reqHdrLoc = TS_NULL_MLOC;
503
504 PrefetchDebug("event: %s (%d)", getEventName(event), event);
505
506 TSEvent retEvent = TS_EVENT_HTTP_CONTINUE;
507
508 // For these cases we need to access the client request
509 switch (event) {
510 case TS_EVENT_HTTP_POST_REMAP:
511 case TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE:
512 case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
513 if (TS_SUCCESS != TSHttpTxnClientReqGet(txnp, &reqBuffer, &reqHdrLoc)) {
514 PrefetchError("failed to get client request");
515 TSHttpTxnReenable(txnp, TS_EVENT_HTTP_ERROR);
516 return 0;
517 }
518 break;
519 default:
520 break;
521 }
522
523 switch (event) {
524 case TS_EVENT_HTTP_POST_REMAP: {
525 /* Use the cache key since this has better lookup behavior when using plugins like the cachekey plugin,
526 * for example multiple URIs can match a single cache key */
527 if (data->frontend() && data->secondPass()) {
528 /* Create a separate cache key name space to be used only for front-end and second-pass fetch policy checks. */
529 data->_cachekey.assign("/prefetch");
530 }
531 if (!appendCacheKey(txnp, reqBuffer, data->_cachekey)) {
532 PrefetchError("failed to get the cache key");
533 TSHttpTxnReenable(txnp, TS_EVENT_HTTP_ERROR);
534 return 0;
535 }
536
537 if (data->frontend()) {
538 /* front-end instance */
539 if (data->firstPass()) {
540 /* first-pass */
541 if (!config.isExactMatch()) {
542 data->_fetchable = state->acquire(data->_cachekey);
543 PrefetchDebug("request is %s fetchable", data->_fetchable ? " " : " not ");
544 }
545 }
546 }
547 } break;
548
549 case TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE: {
550 if (data->frontend()) {
551 /* front-end instance */

Callers

nothing calls this directly

Calls 15

TSContDataGetFunction · 0.85
TSHttpTxnClientReqGetFunction · 0.85
TSHttpTxnReenableFunction · 0.85
appendCacheKeyFunction · 0.85
isFetchableFunction · 0.85
shortcutResponseFunction · 0.85
getPristineUrlPathFunction · 0.85
getPristineUrlQueryFunction · 0.85
respToTriggerPrefetchFunction · 0.85
getCmcdNorFunction · 0.85
TSHttpTxnClientRespGetFunction · 0.85
TSHttpHdrReasonLookupFunction · 0.85

Tested by

no test coverage detected