This is an automated email from the ASF dual-hosted git repository. zwoop pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 919b9fa traffic_dump: Make client-request gathered in a global hook (#6500) 919b9fa is described below commit 919b9fa6b3d7366cda181aab0172c32308945360 Author: Brian Neradt <brian.ner...@gmail.com> AuthorDate: Tue Mar 10 21:31:26 2020 -0500 traffic_dump: Make client-request gathered in a global hook (#6500) This will make client-request dumps more accurate to what the client sent since it will allow us to capture the data before other plugins modify it if they register their handler with a global TS_HTTP_READ_REQUEST_HDR_HOOK. (This assumes traffic_dump.so is placed at the top of the plugin.config list.) Co-authored-by: bneradt <bner...@verizonmedia.com> (cherry picked from commit 41b8ea001c496f92ae50977fb78f3aedc64892fa) --- plugins/experimental/traffic_dump/traffic_dump.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/plugins/experimental/traffic_dump/traffic_dump.cc b/plugins/experimental/traffic_dump/traffic_dump.cc index b802c91..9241c2d 100644 --- a/plugins/experimental/traffic_dump/traffic_dump.cc +++ b/plugins/experimental/traffic_dump/traffic_dump.cc @@ -297,9 +297,9 @@ write_message_node_no_content(TSMBuffer &buffer, TSMLoc &hdr_loc) TSMLoc field_loc = TSMimeHdrFieldGet(buffer, hdr_loc, 0); while (field_loc) { TSMLoc next_field_loc; - const char *name; - const char *value; - int name_len, value_len; + const char *name = nullptr; + const char *value = nullptr; + int name_len = 0, value_len = 0; // Append to "fields" list if valid value exists if ((name = TSMimeHdrFieldNameGet(buffer, hdr_loc, field_loc, &name_len)) && name_len) { value = TSMimeHdrFieldValueStringGet(buffer, hdr_loc, field_loc, -1, &value_len); @@ -415,6 +415,11 @@ session_txn_handler(TSCont contp, TSEvent event, void *edata) } case TS_EVENT_HTTP_READ_REQUEST_HDR: { + // This hook is registered globally, not at TS_EVENT_HTTP_SSN_START in + // global_ssn_handler(). As such, this handler will be called with every + // transaction. However, we know that we are dumping this transaction + // because there is a ssnData associated with it. + // We must grab the client request information before remap happens because // the remap process modifies the request buffer. TSMBuffer buffer; @@ -437,6 +442,8 @@ session_txn_handler(TSCont contp, TSEvent event, void *edata) TSMLoc hdr_loc; if (TS_SUCCESS == TSHttpTxnClientReqGet(txnp, &buffer, &hdr_loc)) { txn_info += write_content_node(TSHttpTxnClientReqBodyBytesGet(txnp)) + "}"; + TSHandleMLocRelease(buffer, TS_NULL_MLOC, hdr_loc); + buffer = nullptr; } if (TS_SUCCESS == TSHttpTxnServerReqGet(txnp, &buffer, &hdr_loc)) { TSDebug(PLUGIN_NAME, "Found proxy request"); @@ -585,7 +592,6 @@ global_ssn_handler(TSCont contp, TSEvent event, void *edata) TSMutexUnlock(ssnData->disk_io_mutex); TSHttpSsnHookAdd(ssnp, TS_HTTP_TXN_START_HOOK, ssnData->txn_cont); - TSHttpSsnHookAdd(ssnp, TS_HTTP_READ_REQUEST_HDR_HOOK, ssnData->txn_cont); TSHttpSsnHookAdd(ssnp, TS_HTTP_TXN_CLOSE_HOOK, ssnData->txn_cont); break; } @@ -673,6 +679,13 @@ TSPluginInit(int argc, const char *argv[]) TSCont ssncont = TSContCreate(global_ssn_handler, nullptr); TSHttpHookAdd(TS_HTTP_SSN_START_HOOK, ssncont); TSHttpHookAdd(TS_HTTP_SSN_CLOSE_HOOK, ssncont); + + // Register the collecting of client-request headers at the global level so + // we can process requests before other plugins. (Global hooks are + // processed before session and transaction ones.) + TSCont txn_cont = TSContCreate(session_txn_handler, nullptr); + TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, txn_cont); + TSLifecycleHookAdd(TS_LIFECYCLE_MSG_HOOK, ssncont); TSDebug(PLUGIN_NAME, "Initialized with sample pool size %" PRId64 " bytes and disk limit %" PRId64 " bytes", sample_pool_size.load(), max_disk_usage.load());