From ef9fd98ce0bcc02fd804a0dca19a561ba084c53a Mon Sep 17 00:00:00 2001 From: Piotr Konieczny Date: Mon, 19 May 2014 14:30:45 +0200 Subject: [PATCH] Added follow_location functionality to JHttpTransportSocket --- libraries/joomla/http/transport/socket.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/http/transport/socket.php b/libraries/joomla/http/transport/socket.php index f32a520b0ae49..e3441cb9c1c4a 100644 --- a/libraries/joomla/http/transport/socket.php +++ b/libraries/joomla/http/transport/socket.php @@ -142,7 +142,20 @@ public function request($method, JUri $uri, $data = null, array $headers = null, $content .= fgets($connection, 4096); } - return $this->getResponse($content); + $content = $this->getResponse($content); + + /* Wikipedia says: A user agent should not automatically redirect a request more than five times, + * since such redirections usually indicate an infinite loop + * + * However JHttpTransportCurl doesn't set CURLOPT_MAXREDIRS, JHttpTransportStream uses max_redirects default 20 + * so let's rely on severs' sanity :D + */ + if ($content->code >= 301 && $content->code < 400 && isset($content->headers['Location'])) + { + return $this->request($method, new JUri($content->headers['Location']), $data, $headers, $timeout, $userAgent); + } + + return $content; } /**