if (request == null) {
throw new IllegalStateException
("Request must not be null.");
}
// If we have a forced route, we can do without a target.
HttpRoute route =
ConnRouteParams.getForcedRoute(request.getParams());
if (route != null)
return route;
// If we get here, there is no forced route.
// So we need a target to compute a route.
if (target == null) {
throw new IllegalStateException
("Target host must not be null.");
}
final InetAddress local =
ConnRouteParams.getLocalAddress(request.getParams());
final HttpHost proxy =
ConnRouteParams.getDefaultProxy(request.getParams());
final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
// as it is typically used for TLS/SSL, we assume that
// a layered scheme implies a secure connection
final boolean secure = schm.isLayered();
if (proxy == null) {
route = new HttpRoute(target, local, secure);
} else {
route = new HttpRoute(target, local, proxy, secure);
}
return route;