Perhaps something like, if the redirected url is within the same domain, then follow otherwise don't. Another option might be to use conditions.

Comments

Deciphered’s picture

I've implemented the 'max_redirects' parameter in #2149329: Expose entire functionality of drupal_http_request()., not exactly the same thing but similar.