From: Rainer Jung Date: Sun, 13 Jul 2014 14:20:04 +0000 (+0000) Subject: Forward local IP address as a custom request attribute X-Git-Tag: 2.5.0-alpha~3980 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e3b46844ffac4e18c7dc16161c64a46967882a3;p=apache Forward local IP address as a custom request attribute like we already do for the remote port. Both were forgotten in the original AJP 13 spec but are needed by the Servlet spec. Until now, Tomcat simply returns for getLocalAddr() the same as for getLocalName(). The next round of Tomcat releases will look for the optional new request attribute. See also Tomcat BZ 56661. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1610207 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/log-message-tags/next-number b/docs/log-message-tags/next-number index e61b97bd4e..8634b83fcb 100644 --- a/docs/log-message-tags/next-number +++ b/docs/log-message-tags/next-number @@ -1 +1 @@ -2646 +2647 diff --git a/modules/proxy/ajp_header.c b/modules/proxy/ajp_header.c index 074f0a8d05..8f9a2fcd3d 100644 --- a/modules/proxy/ajp_header.c +++ b/modules/proxy/ajp_header.c @@ -435,6 +435,26 @@ static apr_status_t ajp_marshal_into_msgb(ajp_msg_t *msg, return AJP_EOVERFLOW; } } + /* Forward the local ip address information, which was forgotten + * from the builtin data of the AJP 13 protocol. + * Since the servlet spec allows to retrieve it via getLocalAddr(), + * we provide the address to the Tomcat connector as a request + * attribute. Modern Tomcat versions know how to retrieve + * the local address from this attribute. + */ + { + const char *key = SC_A_REQ_LOCAL_ADDR; + char *val = r->connection->local_ip; + if (ajp_msg_append_uint8(msg, SC_A_REQ_ATTRIBUTE) || + ajp_msg_append_string(msg, key) || + ajp_msg_append_string(msg, val)) { + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02646) + "ajp_marshal_into_msgb: " + "Error appending attribute %s=%s", + key, val); + return AJP_EOVERFLOW; + } + } /* Use the environment vars prefixed with AJP_ * and pass it to the header striping that prefix. */ diff --git a/modules/proxy/ajp_header.h b/modules/proxy/ajp_header.h index 22d890802c..0f5fdaa81e 100644 --- a/modules/proxy/ajp_header.h +++ b/modules/proxy/ajp_header.h @@ -51,6 +51,11 @@ * to contain the forwarded remote port. */ #define SC_A_REQ_REMOTE_PORT ("AJP_REMOTE_PORT") +/* + * The following request attribute is recognized by Tomcat + * to contain the forwarded local ip address. + */ +#define SC_A_REQ_LOCAL_ADDR ("AJP_LOCAL_ADDR") /* * Request methods, coded as numbers instead of strings.