mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-03-14 20:21:14 +03:00
fix: connectivityaction (#2725)
This commit is contained in:
parent
7a87a09fc5
commit
0212c4790f
2 changed files with 16 additions and 10 deletions
|
@ -83,12 +83,10 @@ class ConnectivityAction extends ActionAbstract {
|
|||
try {
|
||||
$reply = getContents($bridge::URI, array(), $curl_opts, true);
|
||||
|
||||
if($reply) {
|
||||
if($reply['code'] === 200) {
|
||||
$retVal['successful'] = true;
|
||||
if (isset($reply['header'])) {
|
||||
if (strpos($reply['header'], 'HTTP/1.1 301 Moved Permanently') !== false) {
|
||||
$retVal['http_code'] = 301;
|
||||
}
|
||||
if (strpos(implode('', $reply['status_lines']), '301 Moved Permanently')) {
|
||||
$retVal['http_code'] = 301;
|
||||
}
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
|
|
|
@ -49,14 +49,14 @@ const RSSBRIDGE_HTTP_STATUS_CODES = [
|
|||
*
|
||||
* @param array $httpHeaders E.g. ['Content-type: text/plain']
|
||||
* @param array $curlOptions Associative array e.g. [CURLOPT_MAXREDIRS => 3]
|
||||
* @param bool $returnHeader Whether to include headers in the returned value
|
||||
* @param bool $returnFull Whether to return an array ['header' => [...], 'content' => '...']
|
||||
* @return string|array
|
||||
*/
|
||||
function getContents(
|
||||
string $url,
|
||||
array $httpHeaders = [],
|
||||
array $curlOptions = [],
|
||||
bool $returnHeader = false
|
||||
bool $returnFull = false
|
||||
) {
|
||||
$cacheFactory = new CacheFactory();
|
||||
$cacheFactory->setWorkingDir(PATH_LIB_CACHES);
|
||||
|
@ -78,6 +78,8 @@ function getContents(
|
|||
|
||||
$result = _http_request($url, $config);
|
||||
$response = [
|
||||
'code' => $result['code'],
|
||||
'status_lines' => $result['status_lines'],
|
||||
'header' => $result['headers'],
|
||||
'content' => $result['body'],
|
||||
];
|
||||
|
@ -110,7 +112,7 @@ function getContents(
|
|||
)
|
||||
);
|
||||
}
|
||||
if ($returnHeader === true) {
|
||||
if ($returnFull === true) {
|
||||
return $response;
|
||||
}
|
||||
return $response['content'];
|
||||
|
@ -158,10 +160,15 @@ function _http_request(string $url, array $config = []): array
|
|||
curl_setopt($ch, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
|
||||
}
|
||||
|
||||
$responseStatusLines = [];
|
||||
$responseHeaders = [];
|
||||
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $rawHeader) use (&$responseHeaders) {
|
||||
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $rawHeader) use (&$responseHeaders, &$responseStatusLines) {
|
||||
$len = strlen($rawHeader);
|
||||
if (preg_match('#^HTTP/(2|1.1|1.0)#', $rawHeader) || $rawHeader === "\r\n") {
|
||||
if ($rawHeader === "\r\n") {
|
||||
return $len;
|
||||
}
|
||||
if (preg_match('#^HTTP/(2|1.1|1.0)#', $rawHeader)) {
|
||||
$responseStatusLines[] = $rawHeader;
|
||||
return $len;
|
||||
}
|
||||
$header = explode(':', $rawHeader);
|
||||
|
@ -195,6 +202,7 @@ function _http_request(string $url, array $config = []): array
|
|||
curl_close($ch);
|
||||
return [
|
||||
'code' => $statusCode,
|
||||
'status_lines' => $responseStatusLines,
|
||||
'headers' => $responseHeaders,
|
||||
'body' => $data,
|
||||
];
|
||||
|
|
Loading…
Add table
Reference in a new issue