Workaround for curl follow redirect + open base dir restrictions
This commit is contained in:
parent
68a8e8f954
commit
9af4f3db52
2
vendor/PicoFeed/Client.php
vendored
2
vendor/PicoFeed/Client.php
vendored
@ -73,7 +73,7 @@ abstract class Client
|
|||||||
|
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
|
|
||||||
if (strpos($line, 'HTTP') === 0 && strpos($line, '301') === false && strpos($line, '302') === false) {
|
if (strpos($line, 'HTTP') === 0/* && strpos($line, '301') === false && strpos($line, '302') === false*/) {
|
||||||
|
|
||||||
$status = (int) substr($line, 9, 3);
|
$status = (int) substr($line, 9, 3);
|
||||||
}
|
}
|
||||||
|
34
vendor/PicoFeed/Clients/Curl.php
vendored
34
vendor/PicoFeed/Clients/Curl.php
vendored
@ -18,7 +18,6 @@ class Curl extends \PicoFeed\Client
|
|||||||
$this->body_length += $length;
|
$this->body_length += $length;
|
||||||
|
|
||||||
if ($this->body_length > $this->max_body_size) return -1;
|
if ($this->body_length > $this->max_body_size) return -1;
|
||||||
|
|
||||||
$this->body .= $buffer;
|
$this->body .= $buffer;
|
||||||
|
|
||||||
return $length;
|
return $length;
|
||||||
@ -45,7 +44,7 @@ class Curl extends \PicoFeed\Client
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function doRequest()
|
public function doRequest($follow_location = true)
|
||||||
{
|
{
|
||||||
$request_headers = array('Connection: close');
|
$request_headers = array('Connection: close');
|
||||||
|
|
||||||
@ -59,7 +58,7 @@ class Curl extends \PicoFeed\Client
|
|||||||
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
|
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
|
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
|
||||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ini_get('open_basedir') === '');
|
||||||
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects);
|
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects);
|
||||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
curl_setopt($ch, CURLOPT_ENCODING, '');
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // For auto-signed certificates...
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // For auto-signed certificates...
|
||||||
@ -84,6 +83,35 @@ class Curl extends \PicoFeed\Client
|
|||||||
|
|
||||||
list($status, $headers) = $this->parseHeaders(explode("\r\n", $this->headers[$this->headers_counter - 1]));
|
list($status, $headers) = $this->parseHeaders(explode("\r\n", $this->headers[$this->headers_counter - 1]));
|
||||||
|
|
||||||
|
if ($follow_location && ini_get('open_basedir') !== '' && ($status == 301 || $status == 302)) {
|
||||||
|
|
||||||
|
$nb_redirects = 0;
|
||||||
|
$this->url = $headers['Location'];
|
||||||
|
$this->body = '';
|
||||||
|
$this->body_length = 0;
|
||||||
|
$this->headers = array();
|
||||||
|
$this->headers_counter = 0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
$nb_redirects++;
|
||||||
|
if ($nb_redirects >= $this->max_redirects) return false;
|
||||||
|
|
||||||
|
$result = $this->doRequest(false);
|
||||||
|
|
||||||
|
if ($result['status'] == 301 || $result['status'] == 302) {
|
||||||
|
$this->url = $result['headers']['Location'];
|
||||||
|
$this->body = '';
|
||||||
|
$this->body_length = 0;
|
||||||
|
$this->headers = array();
|
||||||
|
$this->headers_counter = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
'body' => $this->body,
|
'body' => $this->body,
|
||||||
|
Loading…
Reference in New Issue
Block a user