///////////////////////////////////////////////////////////////////////// Main "plugin", which is a global TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE hook. Before initiating a background fetch, this checks if a background fetch is allowed for this request
| 112 | // if a background fetch is allowed for this request |
| 113 | // |
| 114 | static int |
| 115 | cont_handle_cache(TSCont contp, TSEvent event, void *edata) |
| 116 | { |
| 117 | TSHttpTxn txnp = static_cast<TSHttpTxn>(edata); |
| 118 | BgFetchConfig *config = static_cast<BgFetchConfig *>(TSContDataGet(contp)); |
| 119 | |
| 120 | if (nullptr == config) { |
| 121 | // something seriously wrong.. |
| 122 | TSError("[%s] Can't get configurations", PLUGIN_NAME); |
| 123 | } else if (config->bgFetchAllowed(txnp)) { |
| 124 | if (TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE == event) { |
| 125 | bool const requested = cont_check_cacheable(txnp); |
| 126 | if (requested) // Made a background fetch request, do not cache the response |
| 127 | { |
| 128 | Dbg(dbg_ctl, "setting no store"); |
| 129 | TSHttpTxnCntlSet(txnp, TS_HTTP_CNTL_SERVER_NO_STORE, true); |
| 130 | TSHttpTxnCacheLookupStatusSet(txnp, TS_CACHE_LOOKUP_MISS); |
| 131 | } |
| 132 | |
| 133 | } else { |
| 134 | TSError("[%s] Unknown event for this plugin %d", PLUGIN_NAME, event); |
| 135 | Dbg(dbg_ctl, "unknown event for this plugin %d", event); |
| 136 | } |
| 137 | } |
| 138 | // Reenable and continue with the state machine. |
| 139 | TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | /////////////////////////////////////////////////////////////////////////// |
| 144 | // Setup global hooks |
nothing calls this directly
no test coverage detected