Followup to r756926 (forward remote port via AJP13).
authorrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 22 Mar 2009 17:55:35 +0000 (17:55 +0000)
committerrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 22 Mar 2009 17:55:35 +0000 (17:55 +0000)
- 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
java/org/apache/coyote/ajp/AjpProcessor.java
java/org/apache/coyote/ajp/Constants.java
java/org/apache/jk/common/AjpConstants.java
java/org/apache/jk/common/HandlerRequest.java

index 560b457..98f8799 100644 (file)
@@ -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;
 
index f4e20b3..38f92d5 100644 (file)
@@ -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;
 
index a5d533d..007fec9 100644 (file)
@@ -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;
 
index 155c93f..df16b90 100644 (file)
@@ -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;
index 0810e7d..b489707 100644 (file)
@@ -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);
                 }
             }