Author: veithen
Date: Thu Sep 22 19:26:48 2011
New Revision: 1174334
URL: http://svn.apache.org/viewvc?rev=1174334&view=rev
Log:
Performance improvement: avoid usage of InetAddress#getHostName(), especially
in contexts where it is more consistent to use the HTTP Host header.
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
Modified:
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java?rev=1174334&r1=1174333&r2=1174334&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
(original)
+++
synapse/trunk/java/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
Thu Sep 22 19:26:48 2011
@@ -250,11 +250,25 @@ public class ServerWorker implements Run
msgContext.setProperty(NhttpConstants.REST_URL_POSTFIX, uri);
String servicePrefix = oriUri.substring(0, oriUri.indexOf(uri));
if (servicePrefix.indexOf("://") == -1) {
- HttpInetConnection inetConn = (HttpInetConnection) conn;
- InetAddress localAddr = inetConn.getLocalAddress();
- if (localAddr != null) {
- servicePrefix = (isHttps ? "https://" : "http://") +
- localAddr.getHostName() + ":" +
inetConn.getLocalPort() + servicePrefix;
+ // If the URL in the request line is not absolute, then we first
try to get the Host
+ // header to build the absolute URL. We only use the local network
address/port of
+ // the HTTP connection if no Host header is present. This is not
only consistent, but
+ // also avoids the overhead of the InetAddress#getHostName()
method.
+ String host;
+ Header hostHeader = request.getFirstHeader(HTTP.TARGET_HOST);
+ if (hostHeader != null) {
+ host = hostHeader.getValue();
+ } else {
+ HttpInetConnection inetConn = (HttpInetConnection) conn;
+ InetAddress localAddr = inetConn.getLocalAddress();
+ if (localAddr != null) {
+ host = localAddr.getHostName() + ":" +
inetConn.getLocalPort();
+ } else {
+ host = null;
+ }
+ }
+ if (host != null) {
+ servicePrefix = (isHttps ? "https://" : "http://") + host +
servicePrefix;
}
}
msgContext.setProperty(NhttpConstants.SERVICE_PREFIX, servicePrefix);