From 2af1c1ec95e88da80725ed2c1f60718ca471c364 Mon Sep 17 00:00:00 2001 From: Randall Meyer Date: Tue, 20 Apr 2021 10:26:39 -0700 Subject: [PATCH 1/2] if transaction status non-success, bypass intercept plugin Don't allow the generator or statichit plugin to intercept the transaction if a prior plugin has changed the transaction status to something non-success. --- plugins/experimental/statichit/statichit.cc | 6 ++++++ plugins/generator/generator.cc | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/plugins/experimental/statichit/statichit.cc b/plugins/experimental/statichit/statichit.cc index 09262844d0f..4c5c6d4f902 100644 --- a/plugins/experimental/statichit/statichit.cc +++ b/plugins/experimental/statichit/statichit.cc @@ -563,6 +563,12 @@ TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* errbu TSRemapStatus TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri) { + const TSHttpStatus txnstat = TSHttpTxnStatusGet(rh); + if (txnstat != TS_HTTP_STATUS_NONE && txnstat != TS_HTTP_STATUS_OK) { + VDEBUG("transaction status_code=%d already set; skipping processing", static_cast(txnstat)); + return TSREMAP_NO_REMAP; + } + StaticHitConfig *cfg = static_cast(ih); if (!cfg) { diff --git a/plugins/generator/generator.cc b/plugins/generator/generator.cc index e33681cd685..c6d018e5904 100644 --- a/plugins/generator/generator.cc +++ b/plugins/generator/generator.cc @@ -732,6 +732,12 @@ TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* errbu TSRemapStatus TSRemapDoRemap(void * /* ih */, TSHttpTxn txn, TSRemapRequestInfo *rri) { + const TSHttpStatus txnstat = TSHttpTxnStatusGet(txn); + if (txnstat != TS_HTTP_STATUS_NONE && txnstat != TS_HTTP_STATUS_OK) { + VDEBUG("transaction status_code=%d already set; skipping processing", static_cast(txnstat)); + return TSREMAP_NO_REMAP; + } + // Check if we should turn off the cache before doing anything else ... CheckCacheable(txn, rri->requestUrl, rri->requestBufp); TSHttpTxnHookAdd(txn, TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK, TxnHook); From 037bc76b38f0d2097767dda5cb9681375bc17f42 Mon Sep 17 00:00:00 2001 From: Randall Meyer Date: Wed, 21 Apr 2021 11:10:24 -0700 Subject: [PATCH 2/2] slice: Cleanup status code checking --- plugins/experimental/slice/slice.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/experimental/slice/slice.cc b/plugins/experimental/slice/slice.cc index dcb63b8595c..f25e6bb5740 100644 --- a/plugins/experimental/slice/slice.cc +++ b/plugins/experimental/slice/slice.cc @@ -46,8 +46,8 @@ read_request(TSHttpTxn txnp, Config *const config) if (!header.hasKey(SLICER_MIME_FIELD_INFO, SLICER_MIME_LEN_INFO)) { // check if any previous plugin has monkeyed with the transaction status TSHttpStatus const txnstat = TSHttpTxnStatusGet(txnp); - if (0 != static_cast(txnstat)) { - DEBUG_LOG("txn status change detected (%d), skipping plugin\n", (int)txnstat); + if (TS_HTTP_STATUS_NONE != txnstat) { + DEBUG_LOG("txn status change detected (%d), skipping plugin\n", static_cast(txnstat)); return false; }