From a6ebd88581883f0bb242d532b33eec5dffcc4068 Mon Sep 17 00:00:00 2001 From: rjung Date: Sun, 22 Mar 2009 17:55:35 +0000 Subject: [PATCH] Followup to r756926 (forward remote port via AJP13). - Use a more private attribute name and define it in the Constants class. - Do not set the attribute on the request, only use it for the remote port. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@757223 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/coyote/ajp/AjpAprProcessor.java | 12 +++++++----- java/org/apache/coyote/ajp/AjpProcessor.java | 12 +++++++----- java/org/apache/coyote/ajp/Constants.java | 5 +++++ java/org/apache/jk/common/AjpConstants.java | 5 +++++ java/org/apache/jk/common/HandlerRequest.java | 16 +++++++++------- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/java/org/apache/coyote/ajp/AjpAprProcessor.java b/java/org/apache/coyote/ajp/AjpAprProcessor.java index 560b45711..98f8799fc 100644 --- a/java/org/apache/coyote/ajp/AjpAprProcessor.java +++ b/java/org/apache/coyote/ajp/AjpAprProcessor.java @@ -715,18 +715,20 @@ public class AjpAprProcessor implements ActionHook { String n = tmpMB.toString(); requestHeaderMessage.getBytes(tmpMB); String v = tmpMB.toString(); - request.setAttribute(n, v); /* * AJP13 misses to forward the remotePort. - * Apache automatically sets REMOTE_PORT to the remote port. - * Allow the user to set "JkEnvVar REMOTE_PORT" and - * let us accept the forwarded port as the remote port. + * Allow the AJP connector to add this info via + * a private request attribute. + * We will accept the forwarded data as the remote port, + * and remove it from the public list of request attributes. */ - if(n.equals("REMOTE_PORT")) { + if(n.equals(Constants.SC_A_REQ_REMOTE_PORT)) { try { request.setRemotePort(Integer.parseInt(v)); } catch (NumberFormatException nfe) { } + } else { + request.setAttribute(n, v); } break; diff --git a/java/org/apache/coyote/ajp/AjpProcessor.java b/java/org/apache/coyote/ajp/AjpProcessor.java index f4e20b35f..38f92d520 100644 --- a/java/org/apache/coyote/ajp/AjpProcessor.java +++ b/java/org/apache/coyote/ajp/AjpProcessor.java @@ -721,18 +721,20 @@ public class AjpProcessor implements ActionHook { String n = tmpMB.toString(); requestHeaderMessage.getBytes(tmpMB); String v = tmpMB.toString(); - request.setAttribute(n, v); /* * AJP13 misses to forward the remotePort. - * Apache automatically sets REMOTE_PORT to the remote port. - * Allow the user to set "JkEnvVar REMOTE_PORT" and - * let us accept the forwarded port as the remote port. + * Allow the AJP connector to add this info via + * a private request attribute. + * We will accept the forwarded data as the remote port, + * and remove it from the public list of request attributes. */ - if(n.equals("REMOTE_PORT")) { + if(n.equals(Constants.SC_A_REQ_REMOTE_PORT)) { try { request.setRemotePort(Integer.parseInt(v)); } catch (NumberFormatException nfe) { } + } else { + request.setAttribute(n, v ); } break; diff --git a/java/org/apache/coyote/ajp/Constants.java b/java/org/apache/coyote/ajp/Constants.java index a5d533de9..007fec9c5 100644 --- a/java/org/apache/coyote/ajp/Constants.java +++ b/java/org/apache/coyote/ajp/Constants.java @@ -88,6 +88,11 @@ public final class Constants { // Used for attributes which are not in the list above public static final byte SC_A_REQ_ATTRIBUTE = 10; + /** + * AJP private request attributes + */ + public static final String SC_A_REQ_REMOTE_PORT = "AJP_REMOTE_PORT"; + // Terminates list of attributes public static final byte SC_A_ARE_DONE = (byte)0xFF; diff --git a/java/org/apache/jk/common/AjpConstants.java b/java/org/apache/jk/common/AjpConstants.java index 155c93f57..df16b9021 100644 --- a/java/org/apache/jk/common/AjpConstants.java +++ b/java/org/apache/jk/common/AjpConstants.java @@ -97,6 +97,11 @@ public class AjpConstants { public static final byte SC_A_REQ_ATTRIBUTE = 10; /** + * AJP private request attributes + */ + public static final String SC_A_REQ_REMOTE_PORT = "AJP_REMOTE_PORT"; + + /** * Terminates list of attributes */ public static final byte SC_A_ARE_DONE = (byte)0xFF; diff --git a/java/org/apache/jk/common/HandlerRequest.java b/java/org/apache/jk/common/HandlerRequest.java index 0810e7dca..b489707c7 100644 --- a/java/org/apache/jk/common/HandlerRequest.java +++ b/java/org/apache/jk/common/HandlerRequest.java @@ -454,20 +454,22 @@ public class HandlerRequest extends JkHandler String n=tmpMB.toString(); msg.getBytes( tmpMB ); String v=tmpMB.toString(); - req.setAttribute(n, v ); - if(log.isTraceEnabled()) - log.trace("jk Attribute set " + n + "=" + v); /* * AJP13 misses to forward the remotePort. - * Apache automatically sets REMOTE_PORT to the remote port. - * Allow the user to set "JkEnvVar REMOTE_PORT" and - * let us accept the forwarded port as the remote port. + * Allow the AJP connector to add this info via + * a private request attribute. + * We will accept the forwarded data as the remote port, + * and remove it from the public list of request attributes. */ - if(n.equals("REMOTE_PORT")) { + if(n.equals(AjpConstants.SC_A_REQ_REMOTE_PORT)) { try { req.setRemotePort(Integer.parseInt(v)); } catch (NumberFormatException nfe) { } + } else { + req.setAttribute(n, v ); + if(log.isTraceEnabled()) + log.trace("jk Attribute set " + n + "=" + v); } } -- 2.11.0