From 824defcf4684faaedc08059b8380b7eadd856501 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Sep 2009 17:22:57 +0200 Subject: Handle relative redirects correctly FS#1741 Ignore-this: a85fdaa1c3aae0315a5f2a51ccbde5a0 Some servers (or scripts) do not send full qualified URLs in the Location header on redirects. darcs-hash:20090904152257-7ad00-a9749251c59e4235723ed18bcb9a8f4d3f4157ba.gz --- inc/HTTPClient.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'inc/HTTPClient.php') diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php index 4dee28b9e..77b227e06 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -343,9 +343,15 @@ class HTTPClient { }else{ $this->redirect_count++; $this->referer = $url; + // handle non-RFC-compliant relative redirects if (!preg_match('/^http/i', $this->resp_headers['location'])){ - $this->resp_headers['location'] = $uri['scheme'].'://'.$uri['host']. - $this->resp_headers['location']; + if($this->resp_headers['location'][0] != '/'){ + $this->resp_headers['location'] = $uri['scheme'].'://'.$uri['host'].':'.$uri['port']. + dirname($uri['path']).'/'.$this->resp_headers['location']; + }else{ + $this->resp_headers['location'] = $uri['scheme'].'://'.$uri['host'].':'.$uri['port']. + $this->resp_headers['location']; + } } // perform redirected request, always via GET (required by RFC) return $this->sendRequest($this->resp_headers['location'],array(),'GET'); -- cgit v1.2.3