Remove accept parameter for head/post again
This commit is contained in:
parent
4aeccd3157
commit
04866195b4
|
@ -27,7 +27,6 @@ use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
function redir_init(App $a) {
|
function redir_init(App $a) {
|
||||||
|
@ -143,7 +142,7 @@ function redir_magic($a, $cid, $url)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test for magic auth on the target system
|
// 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()) {
|
if ($serverret->isSuccess()) {
|
||||||
$separator = strpos($target_url, '?') ? '&' : '?';
|
$separator = strpos($target_url, '?') ? '&' : '?';
|
||||||
$target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url);
|
$target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url);
|
||||||
|
|
|
@ -1204,7 +1204,7 @@ class BBCode
|
||||||
$text = DI::cache()->get($cache_key);
|
$text = DI::cache()->get($cache_key);
|
||||||
|
|
||||||
if (is_null($text)) {
|
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()) {
|
if ($curlResult->isSuccess()) {
|
||||||
$mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
|
$mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
|
||||||
} else {
|
} else {
|
||||||
|
@ -1275,7 +1275,7 @@ class BBCode
|
||||||
return $text;
|
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()) {
|
if ($curlResult->isSuccess()) {
|
||||||
$mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
|
$mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -169,7 +169,7 @@ class Media
|
||||||
// Fetch the mimetype or size if missing.
|
// Fetch the mimetype or size if missing.
|
||||||
if (empty($media['mimetype']) || empty($media['size'])) {
|
if (empty($media['mimetype']) || empty($media['size'])) {
|
||||||
$timeout = DI::config()->get('system', 'xrd_timeout');
|
$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
|
// Workaround for systems that can't handle a HEAD request
|
||||||
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
|
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
|
||||||
|
|
|
@ -35,7 +35,6 @@ use Friendica\Core\System;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
use Friendica\Protocol\Diaspora;
|
use Friendica\Protocol\Diaspora;
|
||||||
|
@ -750,7 +749,7 @@ class Profile
|
||||||
$magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request;
|
$magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request;
|
||||||
|
|
||||||
// We have to check if the remote server does understand /magic without invoking something
|
// 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()) {
|
if ($serverret->isSuccess()) {
|
||||||
Logger::info('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path);
|
Logger::info('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path);
|
||||||
System::externalRedirect($magic_path);
|
System::externalRedirect($magic_path);
|
||||||
|
|
|
@ -59,21 +59,6 @@ interface ICanSendHttpRequests
|
||||||
*/
|
*/
|
||||||
public function fetchFull(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = ''): ICanHandleHttpResponses;
|
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.
|
* 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;
|
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 $method A HTTP request
|
||||||
* @param string $url Url to send to
|
* @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:
|
* @param array $opts (optional parameters) associative array with:
|
||||||
* 'body' => (mixed) setting the body for sending data
|
* '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
|
* 'timeout' => int Timeout in seconds, default system config value or 60 seconds
|
||||||
* 'cookiejar' => path to cookie jar file
|
* 'cookiejar' => path to cookie jar file
|
||||||
* 'header' => header array
|
* 'header' => header array
|
||||||
|
@ -106,20 +116,7 @@ interface ICanSendHttpRequests
|
||||||
*
|
*
|
||||||
* @return ICanHandleHttpResponses
|
* @return ICanHandleHttpResponses
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the original URL of the provided URL
|
* Returns the original URL of the provided URL
|
||||||
|
|
|
@ -63,7 +63,7 @@ class HttpClient implements ICanSendHttpRequests
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@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->profiler->startRecording('network');
|
||||||
$this->logger->debug('Request start.', ['url' => $url, 'method' => $method]);
|
$this->logger->debug('Request start.', ['url' => $url, 'method' => $method]);
|
||||||
|
@ -141,7 +141,8 @@ class HttpClient implements ICanSendHttpRequests
|
||||||
};
|
};
|
||||||
|
|
||||||
if (empty($conf[HttpClientOptions::HEADERS]['Accept'])) {
|
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 {
|
try {
|
||||||
|
@ -167,9 +168,9 @@ class HttpClient implements ICanSendHttpRequests
|
||||||
|
|
||||||
/** {@inheritDoc}
|
/** {@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
|
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}
|
* {@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 = [];
|
$opts = [];
|
||||||
|
|
||||||
|
@ -197,7 +201,7 @@ class HttpClient implements ICanSendHttpRequests
|
||||||
$opts[HttpClientOptions::TIMEOUT] = $timeout;
|
$opts[HttpClientOptions::TIMEOUT] = $timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->request('post', $url, $accept_content, $opts);
|
return $this->request('post', $url, $opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -42,7 +42,6 @@ use Friendica\Model\Post;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
use Friendica\Model\Tag;
|
use Friendica\Model\Tag;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
|
||||||
use Friendica\Network\Probe;
|
use Friendica\Network\Probe;
|
||||||
use Friendica\Util\Crypto;
|
use Friendica\Util\Crypto;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
@ -1014,7 +1013,7 @@ class DFRN
|
||||||
|
|
||||||
$content_type = ($public_batch ? "application/magic-envelope+xml" : "application/json");
|
$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();
|
$xml = $postResult->getBody();
|
||||||
|
|
||||||
$curl_stat = $postResult->getReturnCode();
|
$curl_stat = $postResult->getReturnCode();
|
||||||
|
|
|
@ -3018,7 +3018,7 @@ class Diaspora
|
||||||
if (!intval(DI::config()->get("system", "diaspora_test"))) {
|
if (!intval(DI::config()->get("system", "diaspora_test"))) {
|
||||||
$content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
|
$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();
|
$return_code = $postResult->getReturnCode();
|
||||||
} else {
|
} else {
|
||||||
Logger::notice("test_mode");
|
Logger::notice("test_mode");
|
||||||
|
|
|
@ -157,7 +157,7 @@ class Salmon
|
||||||
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
|
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
|
||||||
|
|
||||||
// slap them
|
// slap them
|
||||||
$postResult = DI::httpClient()->post($url, $salmon, HttpClientAccept::DEFAULT, [
|
$postResult = DI::httpClient()->post($url, $salmon, [
|
||||||
'Content-type' => 'application/magic-envelope+xml',
|
'Content-type' => 'application/magic-envelope+xml',
|
||||||
'Content-length' => strlen($salmon),
|
'Content-length' => strlen($salmon),
|
||||||
]);
|
]);
|
||||||
|
@ -182,7 +182,7 @@ class Salmon
|
||||||
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
|
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
|
||||||
|
|
||||||
// slap them
|
// slap them
|
||||||
$postResult = DI::httpClient()->post($url, $salmon, HttpClientAccept::DEFAULT, [
|
$postResult = DI::httpClient()->post($url, $salmon, [
|
||||||
'Content-type' => 'application/magic-envelope+xml',
|
'Content-type' => 'application/magic-envelope+xml',
|
||||||
'Content-length' => strlen($salmon),
|
'Content-length' => strlen($salmon),
|
||||||
]);
|
]);
|
||||||
|
@ -205,7 +205,7 @@ class Salmon
|
||||||
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
|
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
|
||||||
|
|
||||||
// slap them
|
// slap them
|
||||||
$postResult = DI::httpClient()->post($url, $salmon, HttpClientAccept::DEFAULT, [
|
$postResult = DI::httpClient()->post($url, $salmon, [
|
||||||
'Content-type' => 'application/magic-envelope+xml',
|
'Content-type' => 'application/magic-envelope+xml',
|
||||||
'Content-length' => strlen($salmon)]);
|
'Content-length' => strlen($salmon)]);
|
||||||
$return_code = $postResult->getReturnCode();
|
$return_code = $postResult->getReturnCode();
|
||||||
|
|
|
@ -304,7 +304,7 @@ class HTTPSignature
|
||||||
|
|
||||||
$headers['Content-Type'] = 'application/activity+json';
|
$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();
|
$return_code = $postResult->getReturnCode();
|
||||||
|
|
||||||
Logger::info('Transmit to ' . $target . ' returned ' . $return_code);
|
Logger::info('Transmit to ' . $target . ' returned ' . $return_code);
|
||||||
|
@ -452,7 +452,7 @@ class HTTPSignature
|
||||||
$curl_opts[HttpClientOptions::HEADERS] = $header;
|
$curl_opts[HttpClientOptions::HEADERS] = $header;
|
||||||
|
|
||||||
if (!empty($opts['nobody'])) {
|
if (!empty($opts['nobody'])) {
|
||||||
$curlResult = DI::httpClient()->head($request, HttpClientAccept::JSON_AS, $curl_opts);
|
$curlResult = DI::httpClient()->head($request, $curl_opts);
|
||||||
} else {
|
} else {
|
||||||
$curlResult = DI::httpClient()->get($request, HttpClientAccept::JSON_AS, $curl_opts);
|
$curlResult = DI::httpClient()->get($request, HttpClientAccept::JSON_AS, $curl_opts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ class ParseUrl
|
||||||
*/
|
*/
|
||||||
public static function getContentType(string $url, string $accept = HttpClientAccept::DEFAULT)
|
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
|
// Workaround for systems that can't handle a HEAD request
|
||||||
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
|
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
|
||||||
|
|
|
@ -25,7 +25,6 @@ use Friendica\Core\Logger;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\PushSubscriber;
|
use Friendica\Model\PushSubscriber;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
|
||||||
use Friendica\Protocol\OStatus;
|
use Friendica\Protocol\OStatus;
|
||||||
|
|
||||||
class PubSubPublish
|
class PubSubPublish
|
||||||
|
@ -69,7 +68,7 @@ class PubSubPublish
|
||||||
|
|
||||||
Logger::debug('POST', ['headers' => $headers, 'params' => $params]);
|
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();
|
$ret = $postResult->getReturnCode();
|
||||||
|
|
||||||
if ($ret >= 200 && $ret <= 299) {
|
if ($ret >= 200 && $ret <= 299) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user