private DefaultConnectFuture followRedirect(DefaultHttpSession httpSession, IoSessionEx session)
throws URISyntaxException {
HashMap<ResourceOption<?>, Object> overrides = new HashMap<>();
Integer maxRedirects = new Integer((httpSession.getRemoteAddress().getOption(MAXIMUM_REDIRECTS)) - 1);
overrides.put(MAXIMUM_REDIRECTS, maxRedirects);
URI newLocation = new URI(httpSession.getReadHeader("location"));
URI oldLocation = httpSession.getRequestURL();
newLocation = resolveFragement(newLocation, oldLocation);
if (!newLocation.isAbsolute()) {
newLocation = URLUtils.modifyURIPath(oldLocation, newLocation.getPath());
}
String oldQuery = oldLocation.getQuery();
if (oldQuery != null && appendQueryWhenFollowingRedirect) {
newLocation = URLUtils.modifyURIQuery(newLocation, oldQuery);
}
httpSession.setRequestURI(URLUtils.getPathAndQueryURI(newLocation));
ResourceAddress newConnectAddress = addressFactory.newResourceAddress(newLocation.toString(),
new WrappedResourceOptionsForConnectionRetry(httpSession, overrides));
return retryConnect(httpSession, session, newConnectAddress);
}