You can modify your NettyClientHandler
to check for 302 Redirects, and open a new connection to handle the HTML content of the redirect.
Changes made to NettyClientHandler
:
//We know this is a redirect...
if(response.getStatus().code() == HttpResponseStatus.FOUND.code()){//When its a 302...
if(response.headers().names().contains("Location"))
{
System.out.println("We have a redirect...");
//Now we will do the process over to get the actual content...
Main.main(new String[]{response.headers().get("Location")});
}
}
Changes made to main()
as an example to handle the content of the redirect:
String urlPlace = "http://initial.com";
if(args != null && args.length > 0)
{
urlPlace = args[0];
}
URI uri = new URI(urlPlace);
String host = uri.getHost();
int port = uri.getPort();
if(port == -1)
{
port = 80;
}
When we get a HTTP Status code 302, it is the "servers" responsibility to set the Location header for the new URL location in order for the client to handle appropriately.
See Wikipedia 302