trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject trafficserver git commit: TS-2427 Makes the debug header configurable
Date Wed, 21 Oct 2015 15:23:16 GMT
Repository: trafficserver
Updated Branches:
  refs/heads/master 315b6e9a5 -> 70f23c7d7


TS-2427 Makes the debug header configurable

The default is still X-Debug, but can now be overriden with e.g.

    xdebug.so --header=ATS-Zwooped


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/70f23c7d
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/70f23c7d
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/70f23c7d

Branch: refs/heads/master
Commit: 70f23c7d76b51126c586b1e87ed8d11988e68d01
Parents: 315b6e9
Author: Leif Hedstrom <zwoop@apache.org>
Authored: Tue Sep 8 13:43:49 2015 -0600
Committer: Leif Hedstrom <zwoop@apache.org>
Committed: Wed Oct 21 09:17:49 2015 -0600

----------------------------------------------------------------------
 doc/reference/plugins/xdebug.en.rst   | 14 +++++++---
 plugins/experimental/xdebug/xdebug.cc | 45 ++++++++++++++++++++++++------
 2 files changed, 47 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/70f23c7d/doc/reference/plugins/xdebug.en.rst
----------------------------------------------------------------------
diff --git a/doc/reference/plugins/xdebug.en.rst b/doc/reference/plugins/xdebug.en.rst
index 16e0e76..3e041f4 100644
--- a/doc/reference/plugins/xdebug.en.rst
+++ b/doc/reference/plugins/xdebug.en.rst
@@ -21,15 +21,21 @@ XDebug Plugin
   under the License.
 
 The `XDebug` plugin allows HTTP clients to debug the operation of
-the Traffic Server cache using the ``X-Debug`` header. The plugin
-is triggered by the presence of the ``X-Debug`` header in the client
-request. The contents of this header should be the names of the
+the Traffic Server cache using the default ``X-Debug`` header. The plugin
+is triggered by the presence of the ``X-Debug`` or the configured header in
+the client request. The contents of this header should be the names of the
 debug headers that are desired in the response. The `XDebug` plugin
 will remove the ``X-Debug`` header from the client request and
 inject the desired headers into the client response.
 
 `XDebug` is a global plugin. It is installed by adding it to the
-:file:`plugin.config` file.
+:file:`plugin.config` file. It currently takes a single, optional
+configuration option, ``--header``. E.g.
+
+    --header=ATS-My-Debug
+
+This overrides the default ``X-Debug`` header name.
+
 
 Debugging Headers
 =================

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/70f23c7d/plugins/experimental/xdebug/xdebug.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/xdebug/xdebug.cc b/plugins/experimental/xdebug/xdebug.cc
index 8cac135..637b37c 100644
--- a/plugins/experimental/xdebug/xdebug.cc
+++ b/plugins/experimental/xdebug/xdebug.cc
@@ -16,14 +16,19 @@
  * limitations under the License.
  */
 
-#include <ts/ts.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <strings.h>
+#include <getopt.h>
+
+#include "ts/ts.h"
 #include "ts/ink_defs.h"
 
-// The name of the debug request header. This should probably be configurable.
-#define X_DEBUG_HEADER "X-Debug"
+struct {
+  const char *str;
+  int len;
+} xDebugHeader = {NULL, 0};
+
 
 #define XHEADER_X_CACHE_KEY 0x0004u
 #define XHEADER_X_MILESTONES 0x0008u
@@ -286,10 +291,10 @@ XScanRequestHeaders(TSCont /* contp */, TSEvent event, void *edata)
     goto done;
   }
 
-  TSDebug("xdebug", "scanning for %s header values", X_DEBUG_HEADER);
+  TSDebug("xdebug", "scanning for %s header values", xDebugHeader.str);
 
   // Walk the X-Debug header values and determine what to inject into the response.
-  field = TSMimeHdrFieldFind(buffer, hdr, X_DEBUG_HEADER, lengthof(X_DEBUG_HEADER));
+  field = TSMimeHdrFieldFind(buffer, hdr, xDebugHeader.str, xDebugHeader.len);
   while (field != TS_NULL_MLOC) {
     int count = TSMimeHdrFieldValuesCount(buffer, hdr, field);
 
@@ -347,8 +352,10 @@ done:
 }
 
 void
-TSPluginInit(int /* argc */, const char * /*argv */ [])
+TSPluginInit(int argc, const char *argv[])
 {
+  static const struct option longopt[] = {{const_cast<char *>("header"), required_argument,
NULL, 'h'},
+                                          {NULL, no_argument, NULL, '\0'}};
   TSPluginRegistrationInfo info;
 
   info.plugin_name = (char *)"xdebug";
@@ -359,10 +366,32 @@ TSPluginInit(int /* argc */, const char * /*argv */ [])
     TSError("[xdebug] Plugin registration failed");
   }
 
-  TSReleaseAssert(TSHttpArgIndexReserve("xdebug", "xdebug header requests", &XArgIndex)
== TS_SUCCESS);
+  optind = 0;
 
-  TSReleaseAssert(XInjectHeadersCont = TSContCreate(XInjectResponseHeaders, NULL));
+  // Parse the arguments
+  while (true) {
+    int opt = getopt_long(argc, (char *const *)argv, "", longopt, NULL);
+
+    switch (opt) {
+    case 'h':
+      xDebugHeader.str = TSstrdup(optarg);
+      break;
+    }
+
+    if (opt == -1) {
+      break;
+    }
+  }
+
+  if (NULL == xDebugHeader.str) {
+    xDebugHeader.str = TSstrdup("X-Debug"); // We malloc this, for consistency for future
plugin unload events
+  }
+  xDebugHeader.len = strlen(xDebugHeader.str);
 
+
+  // Setup the global hook
+  TSReleaseAssert(TSHttpArgIndexReserve("xdebug", "xdebug header requests", &XArgIndex)
== TS_SUCCESS);
+  TSReleaseAssert(XInjectHeadersCont = TSContCreate(XInjectResponseHeaders, NULL));
   TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(XScanRequestHeaders, NULL));
 }
 


Mime
View raw message