X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNetwork%2FCurlResult.php;h=017f2c559f944ae10fa500dff30d3fbaaac3131d;hb=befc2af5043a3afde251721c0d27df695db1bb7e;hp=a8dd3dd63161ab8a82ff0570d6b8cedc190190a9;hpb=5cdeb8615fb9233be02d3b7257eabac4f064cb99;p=friendica.git diff --git a/src/Network/CurlResult.php b/src/Network/CurlResult.php index a8dd3dd631..017f2c559f 100644 --- a/src/Network/CurlResult.php +++ b/src/Network/CurlResult.php @@ -1,8 +1,28 @@ . + * + */ namespace Friendica\Network; use Friendica\Core\Logger; +use Friendica\Core\System; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\Network; @@ -26,6 +46,11 @@ class CurlResult */ private $header; + /** + * @var array the HTTP headers of the Curl call + */ + private $header_fields; + /** * @var boolean true (if HTTP 2xx result) or false */ @@ -106,7 +131,7 @@ class CurlResult $this->errorNumber = $errorNumber; $this->error = $error; - Logger::log($url . ': ' . $this->returnCode . " " . $result, Logger::DATA); + Logger::debug('construct', ['url' => $url, 'returncode' => $this->returnCode, 'result' => $result]); $this->parseBodyHeader($result); $this->checkSuccess(); @@ -129,6 +154,7 @@ class CurlResult $this->body = substr($result, strlen($header)); $this->header = $header; + $this->header_fields = []; // Is filled on demand } private function checkSuccess() @@ -141,8 +167,8 @@ class CurlResult } if (!$this->isSuccess) { - Logger::log('error: ' . $this->url . ': ' . $this->returnCode . ' - ' . $this->error, Logger::INFO); - Logger::log('debug: ' . print_r($this->info, true), Logger::DATA); + Logger::notice('http error', ['url' => $this->url, 'code' => $this->returnCode, 'error' => $this->error, 'callstack' => System::callstack(20)]); + Logger::debug('debug', ['info' => $this->info]); } if (!$this->isSuccess && $this->errorNumber == CURLE_OPERATION_TIMEDOUT) { @@ -161,7 +187,7 @@ class CurlResult } if ($this->returnCode == 301 || $this->returnCode == 302 || $this->returnCode == 303 || $this->returnCode== 307) { - $redirect_parts = parse_url(defaults($this->info, 'redirect_url', '')); + $redirect_parts = parse_url($this->info['redirect_url'] ?? ''); if (empty($redirect_parts)) { $redirect_parts = []; } @@ -173,7 +199,7 @@ class CurlResult } } - $parts = parse_url(defaults($this->info, 'url', '')); + $parts = parse_url($this->info['url'] ?? ''); if (empty($parts)) { $parts = []; } @@ -243,6 +269,8 @@ class CurlResult if (isset($headers[$field])) { return $headers[$field]; } + + return ''; } /** @@ -252,7 +280,7 @@ class CurlResult * * @return boolean "true" if header exists */ - public function headerExists(string $field) + public function inHeader(string $field) { $field = strtolower(trim($field)); @@ -268,20 +296,21 @@ class CurlResult */ public function getHeaderArray() { - $headers = []; + if (!empty($this->header_fields)) { + return $this->header_fields; + } + + $this->header_fields = []; - $lines = explode("\n", $this->header); + $lines = explode("\n", trim($this->header)); foreach ($lines as $line) { $parts = explode(':', $line); $headerfield = strtolower(trim(array_shift($parts))); $headerdata = trim(implode(':', $parts)); - - if (!empty($headerdata)) { - $headers[$headerfield] = $headerdata; - } + $this->header_fields[$headerfield] = $headerdata; } - return $headers; + return $this->header_fields; } /**