Follow meta refresh with Commons HttpClient

Having to check the title tag from a lot of different websites I needed a tool that would follow HTTP redirects as well as redirects in meta refresh tags. As a fan of Commons HttpClient, I hacked together some code that does the work.

For the impatient: check out the code here.

The code

The actual code is very simple:

  1. it executes an HTTP GET with a given URL
  2. follows HTTP redirects
  3. finally downloads the contents
  4. checks whether there’s a meta refresh tag
    • starts over at 1. if it found such a tag
  5. returns the content.

Have a look at the class TitleTest here: the private method doGet will be most interesting.

Conclusion

I was wondering why there aren’t that many tools out there which support following meta refresh tags. Since a lot of websites use this feature I thought that this would be something a lot of people might want to use when testing their websites.
Hacking a small tool that does the job is very easy though, as demonstrated in this post.