restlet-framework-java
restlet-framework-java copied to clipboard
HttpURLConnection redirection issue with FollowRedirect as true when using Reslet library
In our application we are using HttpURLConnection restlet library for requests. Initially we were having FollowRedirect=false and redirects were handled by restlet library completely. But recently we faced an issue where restlet library was not able to redirect as "Location" header was null at restlet level.
When we set FollowRedirect=true i.e. enabled redirection handling at HttpURLConnection layer that started working. But with the same we faced a new issue which is as follows:
We are using bitly as short url and have following chain of redirection:
- http:// bit.ly/xxxxx Redirect to http:// destination1 with 301 Status code.
- http:// destination1 Redirect to /destination2 with 302 Status code
This redirection is not working with "FollowRedirect=true", reason we found is that in restlet library sets the "Host" header with initial connection it creates with value as "bit.ly". It is implemented in HeaderUtils.java of restlet org.restlet.engine.header package.
At HttpUrlConnection layer while handling redirection as "host" header is set it continues to use "bit.ly" as host for further redirections also instead of using "/destination1" and "/destination2" as host.
Above behavior results in redirection malfunctioning and not working properly.
Do we have a way by which we can prevent restlet from setting "host" information? Or Anyone has recommendation on solution?