You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2022/06/23 20:27:28 UTC
[tomcat-connectors] branch main updated: Apache: allow to configure an environment variable which provides a request id different from the default one provided by mod_unqiue_id. Especially such an env var can be filled via mod_setenvif from an incoming request header.
This is an automated email from the ASF dual-hosted git repository.
rjung pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-connectors.git
The following commit(s) were added to refs/heads/main by this push:
new 8bd804610 Apache: allow to configure an environment variable which provides a request id different from the default one provided by mod_unqiue_id. Especially such an env var can be filled via mod_setenvif from an incoming request header.
8bd804610 is described below
commit 8bd804610738f8ed81405c72d8498d117ff84346
Author: Rainer Jung <ra...@kippdata.de>
AuthorDate: Thu Jun 23 22:26:08 2022 +0200
Apache: allow to configure an environment variable
which provides a request id different from the default
one provided by mod_unqiue_id. Especially such an env
var can be filled via mod_setenvif from an incoming
request header.
---
native/apache-2.0/mod_jk.c | 25 ++++++++++++++++++++++---
xdocs/reference/apache.xml | 20 ++++++++++++++++++++
2 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/native/apache-2.0/mod_jk.c b/native/apache-2.0/mod_jk.c
index 5e0255be8..f98c6f8ca 100644
--- a/native/apache-2.0/mod_jk.c
+++ b/native/apache-2.0/mod_jk.c
@@ -90,6 +90,7 @@
#define JK_LOG_DEF_FILE ("logs/mod_jk.log")
#define JK_SHM_DEF_FILE ("logs/jk-runtime-status")
+#define JK_ENV_REQUEST_ID ("UNIQUE_ID")
#define JK_ENV_REMOTE_ADDR ("JK_REMOTE_ADDR")
#define JK_ENV_REMOTE_PORT ("JK_REMOTE_PORT")
#define JK_ENV_REMOTE_HOST ("JK_REMOTE_HOST")
@@ -197,6 +198,7 @@ typedef struct
* request information using meta data send by a
* proxy in front of us.
*/
+ char *request_id_indicator;
char *remote_addr_indicator;
char *remote_port_indicator;
char *remote_host_indicator;
@@ -2024,6 +2026,7 @@ static const char *jk_set_worker_indicator(cmd_parms * cmd,
/*
* Directives Handling for setting various environment names
* used to overwrite the following request information:
+ * - request_id
* - remote_addr
* - remote_port
* - remote_host
@@ -2032,6 +2035,16 @@ static const char *jk_set_worker_indicator(cmd_parms * cmd,
* - server_name
* - server_port
*/
+static const char *jk_set_request_id_indicator(cmd_parms * cmd,
+ void *dummy, const char *indicator)
+{
+ server_rec *s = cmd->server;
+ jk_server_conf_t *conf =
+ (jk_server_conf_t *) ap_get_module_config(s->module_config, &jk_module);
+ conf->request_id_indicator = apr_pstrdup(cmd->pool, indicator);
+ return NULL;
+}
+
static const char *jk_set_remote_addr_indicator(cmd_parms * cmd,
void *dummy, const char *indicator)
{
@@ -2571,6 +2584,7 @@ static const command_rec jk_cmds[] = {
/*
* Environment variables used to overwrite the following
* request information which gets forwarded:
+ * - request_id
* - remote_addr
* - remote_port
* - remote_host
@@ -2579,6 +2593,8 @@ static const command_rec jk_cmds[] = {
* - server_name
* - server_port
*/
+ AP_INIT_TAKE1("JkRequestIdIndicator", jk_set_request_id_indicator, NULL, RSRC_CONF,
+ "Name of the Apache environment that contains the request id."),
AP_INIT_TAKE1("JkRemoteAddrIndicator", jk_set_remote_addr_indicator, NULL, RSRC_CONF,
"Name of the Apache environment that contains the remote address"),
AP_INIT_TAKE1("JkRemotePortIndicator", jk_set_remote_port_indicator, NULL, RSRC_CONF,
@@ -2769,7 +2785,7 @@ static int jk_handler(request_rec * r)
rconf->rule_extensions = NULL;
rconf->orig_uri = NULL;
rconf->request_id = get_env_string(r, NULL,
- "UNIQUE_ID", 1);
+ xconf->request_id_indicator, 1);
ap_set_module_config(r->request_config, &jk_module, rconf);
}
l->id = rconf->request_id;
@@ -3113,6 +3129,7 @@ static void *create_jk_config(apr_pool_t * p, server_rec * s)
* request information using meta data send by a
* proxy in front of us.
*/
+ c->request_id_indicator = JK_ENV_REQUEST_ID;
c->remote_addr_indicator = JK_ENV_REMOTE_ADDR;
c->remote_port_indicator = JK_ENV_REMOTE_PORT;
c->remote_host_indicator = JK_ENV_REMOTE_HOST;
@@ -3192,6 +3209,8 @@ static void *merge_jk_config(apr_pool_t * p, void *basev, void *overridesv)
if (!overrides->worker_indicator)
overrides->worker_indicator = base->worker_indicator;
+ if (!overrides->request_id_indicator)
+ overrides->request_id_indicator = base->request_id_indicator;
if (!overrides->remote_addr_indicator)
overrides->remote_addr_indicator = base->remote_addr_indicator;
if (!overrides->remote_port_indicator)
@@ -3848,7 +3867,7 @@ static int jk_translate(request_rec * r)
JK_TRACE_ENTER(l);
rconf->request_id = get_env_string(r, NULL,
- "UNIQUE_ID", 1);
+ conf->request_id_indicator, 1);
l->id = rconf->request_id;
if ((r->handler != NULL) && (!strcmp(r->handler, JK_HANDLER))) {
/* Somebody already set the handler, probably manual config
@@ -4058,7 +4077,7 @@ static int jk_map_to_storage(request_rec * r)
&jk_module);
if (conf) {
rconf->request_id = get_env_string(r, NULL,
- "UNIQUE_ID", 1);
+ conf->request_id_indicator, 1);
}
}
diff --git a/xdocs/reference/apache.xml b/xdocs/reference/apache.xml
index 17db68aa6..cf2f62a66 100644
--- a/xdocs/reference/apache.xml
+++ b/xdocs/reference/apache.xml
@@ -337,6 +337,26 @@ to add <code>SSLOptions +ExportCertData</code>.
environment variables or as request headers.
</p>
</attribute>
+<attribute name="JkRequestIdIndicator" required="false">
+<p>
+Name of the Apache environment variable that contains a unique request id.
+The value of the environment variable will be added to most mod_jk error
+log lines and allows easy correlation with Apache logs by adding that
+environment variable there as well.
+<br/>
+The default value is "UNIQUE_ID". Loading the module "mod_unique_id"
+will automatically provide a unique request id under that name.
+</p>
+<p>
+If a request id is sent by the client or another reverse proxy in front via
+an HTTP request header, one can make this id available for mod_jk by
+copying it to an environment variable using mod_headers:<br/>
+<code>SetEnvIf X-REQUEST-ID-HEADER "(.+)" X-REQUEST-ID=$1</code><br/>
+copies the value of the incoming header <code>X-REQUEST-ID-HEADER</code>
+to the environment variable <code>X-REQUEST-ID</code>. mod_jk can
+pick it up from there via <code>JkRequestIdIndicator X-REQUEST-ID</code>.
+</p>
+</attribute>
<attribute name="JkHTTPSIndicator" required="false"><p>
Name of the Apache environment variable that contains SSL indication.
<br/>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org