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) {
}
// 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);
$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 {
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 {
// 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)) {
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;
$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);
public function fetchFull(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = ''): ICanHandleHttpResponses;
/**
- * Send a HEAD to a URL.
+ * Send a GET to a URL.
*
- * @param string $url URL to fetch
+ * @param string $url URL to get
* @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)
*
* @return ICanHandleHttpResponses
*/
- public function head(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses;
+ public function get(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): ICanHandleHttpResponses;
/**
- * Send a GET to a URL.
+ * Send a HEAD to a URL.
*
- * @param string $url URL to get
- * @param string $accept_content supply Accept: header with 'accept_content' as the value
+ * @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
*
* @return ICanHandleHttpResponses
*/
- public function get(string $url, string $accept_content = HttpClientAccept::DEFAULT, array $opts = []): 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 a HTTP request to a given url
+ * 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
*
* @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
/**
* {@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]);
};
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 {
/** {@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);
}
/**
*/
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 = [];
$opts[HttpClientOptions::TIMEOUT] = $timeout;
}
- return $this->request('post', $url, $accept_content, $opts);
+ return $this->request('post', $url, $opts);
}
/**
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;
$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();
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");
$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),
]);
$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),
]);
$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();
$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);
$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);
}
*/
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)) {
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\PushSubscriber;
-use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Protocol\OStatus;
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) {