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

Function cont_check_cacheable

plugins/background_fetch/background_fetch.cc:463–501  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////// This is a TXN hook, used to verify that the response (before sending to originating client) is indeed cacheable. This has to be deferred, because we might have plugins that changes the cacheability of an Origin response.

Source from the content-addressed store, hash-verified

461// we might have plugins that changes the cacheability of an Origin response.
462//
463static int
464cont_check_cacheable(TSCont contp, TSEvent /* event ATS_UNUSED */, void *edata)
465{
466 // ToDo: If we want to support per-remap configurations, we have to pass along the data here
467 TSHttpTxn txnp = static_cast<TSHttpTxn>(edata);
468 TSMBuffer response, request;
469 TSMLoc resp_hdr, req_hdr;
470
471 if (TS_SUCCESS == TSHttpTxnServerRespGet(txnp, &response, &resp_hdr)) {
472 if (TS_SUCCESS == TSHttpTxnClientReqGet(txnp, &request, &req_hdr)) {
473 // Temporarily change the response status to 200 OK, so we can reevaluate cacheability.
474 TSHttpHdrStatusSet(response, resp_hdr, TS_HTTP_STATUS_OK);
475 bool cacheable = TSHttpTxnIsCacheable(txnp, nullptr, response);
476 TSHttpHdrStatusSet(response, resp_hdr, TS_HTTP_STATUS_PARTIAL_CONTENT);
477
478 Dbg(Bg_dbg_ctl, "Testing: request / response is cacheable?");
479 if (cacheable) {
480 BgFetchData *data = new BgFetchData();
481
482 // Initialize the data structure (can fail) and acquire a privileged lock on the URL
483 if (data->initialize(request, req_hdr, txnp) && data->acquireUrl()) {
484 data->schedule();
485 } else {
486 delete data; // Not sure why this would happen, but ok.
487 }
488 }
489 // Release the request MLoc
490 TSHandleMLocRelease(request, TS_NULL_MLOC, req_hdr);
491 }
492 // Release the response MLoc
493 TSHandleMLocRelease(response, TS_NULL_MLOC, resp_hdr);
494 }
495
496 // Reenable and continue with the state machine.
497 TSContDestroy(contp);
498 TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
499
500 return 0;
501}
502
503//////////////////////////////////////////////////////////////////////////////
504// Main "plugin", which is a global READ_RESPONSE_HDR hook. Before

Callers

nothing calls this directly

Calls 10

TSHttpTxnServerRespGetFunction · 0.85
TSHttpTxnClientReqGetFunction · 0.85
TSHttpHdrStatusSetFunction · 0.85
TSHttpTxnIsCacheableFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
TSContDestroyFunction · 0.85
TSHttpTxnReenableFunction · 0.85
initializeMethod · 0.45
acquireUrlMethod · 0.45
scheduleMethod · 0.45

Tested by

no test coverage detected