diff --git a/mod/redir.php b/mod/redir.php index 7ebce17948..d6896f3a80 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -27,7 +27,6 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Profile; -use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Util\Strings; function redir_init(App $a) { @@ -143,7 +142,7 @@ function redir_magic($a, $cid, $url) } // Test for magic auth on the target system - $serverret = DI::httpClient()->head($basepath . '/magic', HttpClientAccept::HTML); + $serverret = DI::httpClient()->head($basepath . '/magic'); if ($serverret->isSuccess()) { $separator = strpos($target_url, '?') ? '&' : '?'; $target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url); diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index bb92640a1d..c9a1bfe052 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1204,7 +1204,7 @@ class BBCode $text = DI::cache()->get($cache_key); if (is_null($text)) { - $curlResult = DI::httpClient()->head($match[1], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); + $curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); if ($curlResult->isSuccess()) { $mimetype = $curlResult->getHeader('Content-Type')[0] ?? ''; } else { @@ -1275,7 +1275,7 @@ class BBCode return $text; } - $curlResult = DI::httpClient()->head($match[1], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); + $curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); if ($curlResult->isSuccess()) { $mimetype = $curlResult->getHeader('Content-Type')[0] ?? ''; } else { diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index ee50061cb8..b783fb6a4f 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -169,7 +169,7 @@ class Media // Fetch the mimetype or size if missing. if (empty($media['mimetype']) || empty($media['size'])) { $timeout = DI::config()->get('system', 'xrd_timeout'); - $curlResult = DI::httpClient()->head($media['url'], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => $timeout]); + $curlResult = DI::httpClient()->head($media['url'], [HttpClientOptions::TIMEOUT => $timeout]); // Workaround for systems that can't handle a HEAD request if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) { diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 2af69d53ac..2b2c1ac97d 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -35,7 +35,6 @@ use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPException; use Friendica\Protocol\Activity; use Friendica\Protocol\Diaspora; @@ -750,7 +749,7 @@ class Profile $magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request; // We have to check if the remote server does understand /magic without invoking something - $serverret = DI::httpClient()->head($basepath . '/magic', HttpClientAccept::HTML); + $serverret = DI::httpClient()->head($basepath . '/magic'); if ($serverret->isSuccess()) { Logger::info('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path); System::externalRedirect($magic_path); diff --git a/src/Network/HTTPClient/Capability/ICanSendHttpRequests.php b/src/Network/HTTPClient/Capability/ICanSendHttpRequests.php index ed42c75455..4c6a725f1b 100644 --- a/src/Network/HTTPClient/Capability/ICanSendHttpRequests.php +++ b/src/Network/HTTPClient/Capability/ICanSendHttpRequests.php @@ -59,21 +59,6 @@ interface ICanSendHttpRequests */ public function fetchFull(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = ''): ICanHandleHttpResponses; - /** - * Send a HEAD to a URL. - * - * @param string $url URL to fetch - * @param string $accept_content supply Accept: header with 'accept_content' as the value - * @param array $opts (optional parameters) associative array with: - * 'accept_content' => (string array) supply Accept: header with 'accept_content' as the value (overrides default parameter) - * 'timeout' => int Timeout in seconds, default system config value or 60 seconds - * 'cookiejar' => path to cookie jar file - * 'header' => header array - * - * @return ICanHandleHttpResponses - */ - public function head(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses; - /** * Send a GET to a URL. * @@ -90,14 +75,39 @@ interface ICanSendHttpRequests public function get(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses; /** - * Sends a HTTP request to a given url + * Send a HEAD to a URL. + * + * @param string $url URL to fetch + * @param array $opts (optional parameters) associative array with: + * 'accept_content' => (string array) supply Accept: header with 'accept_content' as the value (overrides default parameter) + * 'timeout' => int Timeout in seconds, default system config value or 60 seconds + * 'cookiejar' => path to cookie jar file + * 'header' => header array + * + * @return ICanHandleHttpResponses + */ + public function head(string $url, array $opts = []): ICanHandleHttpResponses; + + /** + * Send POST request to an URL + * + * @param string $url URL to post + * @param mixed $params array of POST variables + * @param array $headers HTTP headers + * @param int $timeout The timeout in seconds, default system config value or 60 seconds + * + * @return ICanHandleHttpResponses The content + */ + public function post(string $url, $params, array $headers = [], int $timeout = 0): ICanHandleHttpResponses; + + /** + * Sends an HTTP request to a given url * * @param string $method A HTTP request * @param string $url Url to send to - * @param string $accept_content supply Accept: header with 'accept_content' as the value * @param array $opts (optional parameters) associative array with: * 'body' => (mixed) setting the body for sending data - * 'accept_content' => (string array) supply Accept: header with 'accept_content' as the value (overrides default parameter) + * 'accept_content' => (string array) supply Accept: header with 'accept_content' as the value * 'timeout' => int Timeout in seconds, default system config value or 60 seconds * 'cookiejar' => path to cookie jar file * 'header' => header array @@ -106,20 +116,7 @@ interface ICanSendHttpRequests * * @return ICanHandleHttpResponses */ - public function request(string $method, string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses; - - /** - * Send POST request to an URL - * - * @param string $url URL to post - * @param mixed $params array of POST variables - * @param string $accept_content supply Accept: header with 'accept_content' as the value - * @param array $headers HTTP headers - * @param int $timeout The timeout in seconds, default system config value or 60 seconds - * - * @return ICanHandleHttpResponses The content - */ - public function post(string $url, $params, string $accept_content = HttpClientAccept::DEFAULT, array $headers = [], int $timeout = 0): ICanHandleHttpResponses; + public function request(string $method, string $url, array $opts = []): ICanHandleHttpResponses; /** * Returns the original URL of the provided URL diff --git a/src/Network/HTTPClient/Client/HttpClient.php b/src/Network/HTTPClient/Client/HttpClient.php index da3af042da..28b0f0369e 100644 --- a/src/Network/HTTPClient/Client/HttpClient.php +++ b/src/Network/HTTPClient/Client/HttpClient.php @@ -63,7 +63,7 @@ class HttpClient implements ICanSendHttpRequests /** * {@inheritDoc} */ - public function request(string $method, string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses + public function request(string $method, string $url, array $opts = []): ICanHandleHttpResponses { $this->profiler->startRecording('network'); $this->logger->debug('Request start.', ['url' => $url, 'method' => $method]); @@ -141,7 +141,8 @@ class HttpClient implements ICanSendHttpRequests }; if (empty($conf[HttpClientOptions::HEADERS]['Accept'])) { - $conf[HttpClientOptions::HEADERS]['Accept'] = $accept_content; + $this->logger->info('Accept header was missing, using default.', ['url' => $url, 'callstack' => System::callstack()]); + $conf[HttpClientOptions::HEADERS]['Accept'] = HttpClientAccept::DEFAULT; } try { @@ -167,9 +168,9 @@ class HttpClient implements ICanSendHttpRequests /** {@inheritDoc} */ - public function head(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses + public function head(string $url, array $opts = []): ICanHandleHttpResponses { - return $this->request('head', $url, $accept_content, $opts); + return $this->request('head', $url, $opts); } /** @@ -177,13 +178,16 @@ class HttpClient implements ICanSendHttpRequests */ public function get(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses { - return $this->request('get', $url, $accept_content, $opts); + // In case there is no + $opts[HttpClientOptions::ACCEPT_CONTENT] = $opts[HttpClientOptions::ACCEPT_CONTENT] ?? $accept_content; + + return $this->request('get', $url, $opts); } /** * {@inheritDoc} */ - public function post(string $url, $params, string $accept_content = HttpClientAccept::DEFAULT, array $headers = [], int $timeout = 0): ICanHandleHttpResponses + public function post(string $url, $params, array $headers = [], int $timeout = 0): ICanHandleHttpResponses { $opts = []; @@ -197,7 +201,7 @@ class HttpClient implements ICanSendHttpRequests $opts[HttpClientOptions::TIMEOUT] = $timeout; } - return $this->request('post', $url, $accept_content, $opts); + return $this->request('post', $url, $opts); } /** diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index bd90456c0c..0fb7394579 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -42,7 +42,6 @@ use Friendica\Model\Post; use Friendica\Model\Profile; use Friendica\Model\Tag; use Friendica\Model\User; -use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\Probe; use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; @@ -1014,7 +1013,7 @@ class DFRN $content_type = ($public_batch ? "application/magic-envelope+xml" : "application/json"); - $postResult = DI::httpClient()->post($dest_url, $envelope, HttpClientAccept::DEFAULT, ['Content-Type' => $content_type]); + $postResult = DI::httpClient()->post($dest_url, $envelope, ['Content-Type' => $content_type]); $xml = $postResult->getBody(); $curl_stat = $postResult->getReturnCode(); diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 828237a5e7..71726534d0 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -3018,7 +3018,7 @@ class Diaspora if (!intval(DI::config()->get("system", "diaspora_test"))) { $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json"); - $postResult = DI::httpClient()->post($dest_url . "/", $envelope, HttpClientAccept::DEFAULT, ['Content-Type' => $content_type]); + $postResult = DI::httpClient()->post($dest_url . "/", $envelope, ['Content-Type' => $content_type]); $return_code = $postResult->getReturnCode(); } else { Logger::notice("test_mode"); diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index cf202ba13c..9724f82df7 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -157,7 +157,7 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - $postResult = DI::httpClient()->post($url, $salmon, HttpClientAccept::DEFAULT, [ + $postResult = DI::httpClient()->post($url, $salmon, [ 'Content-type' => 'application/magic-envelope+xml', 'Content-length' => strlen($salmon), ]); @@ -182,7 +182,7 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - $postResult = DI::httpClient()->post($url, $salmon, HttpClientAccept::DEFAULT, [ + $postResult = DI::httpClient()->post($url, $salmon, [ 'Content-type' => 'application/magic-envelope+xml', 'Content-length' => strlen($salmon), ]); @@ -205,7 +205,7 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - $postResult = DI::httpClient()->post($url, $salmon, HttpClientAccept::DEFAULT, [ + $postResult = DI::httpClient()->post($url, $salmon, [ 'Content-type' => 'application/magic-envelope+xml', 'Content-length' => strlen($salmon)]); $return_code = $postResult->getReturnCode(); diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 248e99cb4e..cc25f14918 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -304,7 +304,7 @@ class HTTPSignature $headers['Content-Type'] = 'application/activity+json'; - $postResult = DI::httpClient()->post($target, $content, HttpClientAccept::DEFAULT, $headers); + $postResult = DI::httpClient()->post($target, $content, $headers); $return_code = $postResult->getReturnCode(); Logger::info('Transmit to ' . $target . ' returned ' . $return_code); @@ -452,7 +452,7 @@ class HTTPSignature $curl_opts[HttpClientOptions::HEADERS] = $header; if (!empty($opts['nobody'])) { - $curlResult = DI::httpClient()->head($request, HttpClientAccept::JSON_AS, $curl_opts); + $curlResult = DI::httpClient()->head($request, $curl_opts); } else { $curlResult = DI::httpClient()->get($request, HttpClientAccept::JSON_AS, $curl_opts); } diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index e1adc7dbdd..f3831b52e7 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -61,7 +61,7 @@ class ParseUrl */ public static function getContentType(string $url, string $accept = HttpClientAccept::DEFAULT) { - $curlResult = DI::httpClient()->head($url, $accept); + $curlResult = DI::httpClient()->head($url); // Workaround for systems that can't handle a HEAD request if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) { diff --git a/src/Worker/PubSubPublish.php b/src/Worker/PubSubPublish.php index e8b352950a..e84ac3152e 100644 --- a/src/Worker/PubSubPublish.php +++ b/src/Worker/PubSubPublish.php @@ -25,7 +25,6 @@ use Friendica\Core\Logger; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\PushSubscriber; -use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Protocol\OStatus; class PubSubPublish @@ -69,7 +68,7 @@ class PubSubPublish Logger::debug('POST', ['headers' => $headers, 'params' => $params]); - $postResult = DI::httpClient()->post($subscriber['callback_url'], $params, HttpClientAccept::DEFAULT, $headers); + $postResult = DI::httpClient()->post($subscriber['callback_url'], $params, $headers); $ret = $postResult->getReturnCode(); if ($ret >= 200 && $ret <= 299) {