*/
private int httpsServerPort = 443;
+ private boolean changeLocalPort = false;
+
/**
* @see #setInternalProxies(String)
*/
*/
private String protocolHeaderHttpsValue = "https";
+ private String portHeader = null;
+
/**
* @see #setProxiesHeader(String)
*/
return httpServerPort;
}
+ public boolean isChangeLocalPort() {
+ return changeLocalPort;
+ }
+
+ public void setChangeLocalPort(boolean changeLocalPort) {
+ this.changeLocalPort = changeLocalPort;
+ }
+
+ /**
+ * Obtain the name of the HTTP header used to override the value returned
+ * by {@link Request#getServerPort()} and (optionally depending on {link
+ * {@link #isChangeLocalPort()} {@link Request#getLocalPort()}.
+ *
+ * @return The HTTP header name
+ */
+ public String getPortHeader() {
+ return portHeader;
+ }
+
+ /**
+ * Set the name of the HTTP header used to override the value returned
+ * by {@link Request#getServerPort()} and (optionally depending on {link
+ * {@link #isChangeLocalPort()} {@link Request#getLocalPort()}.
+ *
+ * @param portHeader The HTTP header name
+ */
+ public void setPortHeader(String portHeader) {
+ this.portHeader = portHeader;
+ }
+
/**
* Return descriptive information about this Valve implementation.
*/
// use request.coyoteRequest.scheme instead of request.setScheme() because request.setScheme() is no-op in Tomcat 6.0
request.getCoyoteRequest().scheme().setString("https");
- request.setServerPort(httpsServerPort);
+ setPorts(request, httpsServerPort);
} else {
request.setSecure(false);
// use request.coyoteRequest.scheme instead of request.setScheme() because request.setScheme() is no-op in Tomcat 6.0
request.getCoyoteRequest().scheme().setString("http");
- request.setServerPort(httpServerPort);
+ setPorts(request, httpServerPort);
}
}
request.setServerPort(originalServerPort);
}
}
+
+ private void setPorts(Request request, int defaultPort) {
+ int port = defaultPort;
+ if (portHeader != null) {
+ String portHeaderValue = request.getHeader(portHeader);
+ if (portHeaderValue != null) {
+ try {
+ port = Integer.parseInt(portHeaderValue);
+ } catch (NumberFormatException nfe) {
+ log.debug(sm.getString(
+ "remoteIpValve.invalidPortHeader",
+ portHeaderValue, portHeader), nfe);
+ }
+ }
+ }
+ request.setServerPort(port);
+ if (changeLocalPort) {
+ request.getCoyoteRequest().setLocalPort(port);
+ }
+ }
/**
* <p>
default of <code>null</code> is used.</p>
</attribute>
+ <attribute name="portHeader" required="false">
+ <p>Name of the HTTP Header read by this valve that holds the port
+ used by the client to connect to the proxy. If not specified, the
+ default of <code>null</code> is used.</p>
+ </attribute>
+
<attribute name="protocolHeaderHttpsValue" required="false">
<p>Value of the <strong>protocolHeader</strong> to indicate that it is
an HTTPS request. If not specified, the default of <code>https</code> is
<attribute name="httpServerPort" required="false">
<p>Value returned by <code>ServletRequest.getServerPort()</code>
when the <strong>protocolHeader</strong> indicates <code>http</code>
- protocol. If not specified, the default of <code>80</code> is
- used.</p>
+ protocol and no <strong>portHeader</strong> is present. If not
+ specified, the default of <code>80</code> is used.</p>
</attribute>
<attribute name="httpsServerPort" required="false">
<p>Value returned by <code>ServletRequest.getServerPort()</code>
when the <strong>protocolHeader</strong> indicates <code>https</code>
- protocol. If not specified, the default of <code>443</code> is
- used.</p>
+ protocol and no <strong>portHeader</strong> is present. If not
+ specified, the default of <code>443</code> is used.</p>
</attribute>
+ <attribute name="changeLocalPort" required="false">
+ <p>If <code>true</code>, the value returned by
+ <code>ServletRequest.getLocalPort()</code> and
+ <code>ServletRequest.getServerPort()</code> is modified by the this
+ valve. If not specified, the default of <code>false</code> is used.</p>
+ </attribute>
+
</attributes>
</subsection>