version = null;
}
}
// Set the protocol used for this request
Protocol serverProtocol = getConnection().getHelper().getHelped()
.getProtocols().get(0);
setProtocol(new Protocol(serverProtocol.getSchemeName(),
serverProtocol.getName(), serverProtocol.getDescription(),
serverProtocol.getDefaultPort(),
serverProtocol.isConfidential(), version));
// Parse the host header
String host = (getHeaders() == null) ? null : getHeaders()
.getFirstValue(HeaderConstants.HEADER_HOST, true);
String hostDomain = null;
int hostPort = -1;
if (host != null) {
int colonIndex = host.indexOf(':');
if (colonIndex != -1) {
hostDomain = host.substring(0, colonIndex);
hostPort = Integer.valueOf(host.substring(colonIndex + 1));
} else {
hostDomain = host;
hostPort = getProtocol().getDefaultPort();
}
} else {
if (!Protocol.SIP.getSchemeName().equals(
serverProtocol.getSchemeName())
&& !Protocol.SIPS.getSchemeName().equals(
serverProtocol.getSchemeName())) {
Context.getCurrentLogger()
.info("Couldn't find the mandatory \"Host\" HTTP header. Falling back to the IP address.");
hostDomain = getConnection().getAddress();
hostPort = getConnection().getPort();
if (hostDomain == null) {
hostDomain = "localhost";
}
if (hostPort == -1) {
hostPort = getConnection().getHelper().getHelped()
.getActualPort();
}
if (hostPort == -1) {
getProtocol().getDefaultPort();
}
}
}
// Set the host reference
Protocol protocol = getConnection().getHelper().getHelped()
.getProtocols().get(0);
StringBuilder sb = new StringBuilder();
sb.append(protocol.getSchemeName()).append("://");
sb.append(hostDomain);
if ((hostPort != -1) && (hostPort != protocol.getDefaultPort())) {
sb.append(':').append(hostPort);
}
setHostRef(sb.toString());