$return = Contact::searchByName($search, $mode);
} else {
$p = $page > 1 ? 'p=' . $page : '';
- $curlResult = DI::httpRequest()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), ['accept_content' => 'application/json']);
+ $curlResult = DI::httpRequest()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), ['accept_content' => ['application/json']]);
if ($curlResult->isSuccess()) {
$searchResult = json_decode($curlResult->getBody(), true);
if (!empty($searchResult['profiles'])) {
if (!empty($accesstoken)) {
$api = 'https://instances.social/api/1.0/instances/list?count=0';
- $header = ['Authorization: Bearer '.$accesstoken];
- $curlResult = DI::httpRequest()->get($api, ['header' => $header]);
+ $curlResult = DI::httpRequest()->get($api, ['header' => ['Authorization' => ['Bearer ' . $accesstoken]]]);
if ($curlResult->isSuccess()) {
$servers = json_decode($curlResult->getBody(), true);
}
try {
- $fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, ['accept_content' => '']);
+ $fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, ['accept_content' => []]);
} catch (Exception $exception) {
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception);
}
$request['url'] = str_replace(' ', '+', $request['url']);
// Fetch the content with the local user
- $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['accept_content' => '', 'timeout' => 10]);
+ $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['accept_content' => [], 'timeout' => 10]);
$img_str = $fetchResult->getBody();
if (!$fetchResult->isSuccess() || empty($img_str)) {
$header = [];
if (!empty($opts['accept_content'])) {
- array_push($header, 'Accept: ' . $opts['accept_content']);
+ $header['Accept'] = $opts['accept_content'];
}
if (!empty($opts['header'])) {
Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url, 'callstack' => System::callstack(20)]);
$xrd = null;
- $curlResult = DI::httpRequest()->get($ssl_url, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
+ $curlResult = DI::httpRequest()->get($ssl_url, ['timeout' => $xrd_timeout, 'accept_content' => ['application/xrd+xml']]);
$ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
if ($curlResult->isSuccess()) {
$xml = $curlResult->getBody();
}
if (!is_object($xrd) && !empty($url)) {
- $curlResult = DI::httpRequest()->get($url, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
+ $curlResult = DI::httpRequest()->get($url, ['timeout' => $xrd_timeout, 'accept_content' => ['application/xrd+xml']]);
$connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
if ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $url]);
{
$xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20);
- $curlResult = DI::httpRequest()->get($url, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
+ $curlResult = DI::httpRequest()->get($url, ['timeout' => $xrd_timeout, 'accept_content' => [$type]]);
if ($curlResult->isTimeout()) {
self::$istimeout = true;
return [];
$content_type = ($public_batch ? "application/magic-envelope+xml" : "application/json");
- $postResult = DI::httpRequest()->post($dest_url, $envelope, ["Content-Type: " . $content_type]);
+ $postResult = DI::httpRequest()->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::httpRequest()->post($dest_url . "/", $envelope, ["Content-Type: " . $content_type]);
+ $postResult = DI::httpRequest()->post($dest_url . "/", $envelope, ['Content-Type' => $content_type]);
$return_code = $postResult->getReturnCode();
} else {
Logger::log("test_mode");
self::$conv_list[$conversation] = true;
- $curlResult = DI::httpRequest()->get($conversation, ['accept_content' => 'application/atom+xml, text/html']);
+ $curlResult = DI::httpRequest()->get($conversation, ['accept_content' => ['application/atom+xml', 'text/html']]);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
return;
}
$stored = false;
- $curlResult = DI::httpRequest()->get($related, ['accept_content' => 'application/atom+xml, text/html']);
+ $curlResult = DI::httpRequest()->get($related, ['accept_content' => ['application/atom+xml', 'text/html']]);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
return;
// slap them
$postResult = DI::httpRequest()->post($url, $salmon, [
- 'Content-type: application/magic-envelope+xml',
- 'Content-length: ' . strlen($salmon)
+ 'Content-type' => 'application/magic-envelope+xml',
+ 'Content-length' => strlen($salmon),
]);
$return_code = $postResult->getReturnCode();
// slap them
$postResult = DI::httpRequest()->post($url, $salmon, [
- 'Content-type: application/magic-envelope+xml',
- 'Content-length: ' . strlen($salmon)
+ 'Content-type' => 'application/magic-envelope+xml',
+ 'Content-length' => strlen($salmon),
]);
$return_code = $postResult->getReturnCode();
}
// slap them
$postResult = DI::httpRequest()->post($url, $salmon, [
- 'Content-type: application/magic-envelope+xml',
- 'Content-length: ' . strlen($salmon)]);
+ 'Content-type' => 'application/magic-envelope+xml',
+ 'Content-length' => strlen($salmon)]);
$return_code = $postResult->getReturnCode();
}
use Friendica\Model\Contact;
use Friendica\Model\User;
use Friendica\Network\CurlResult;
+use Friendica\Network\IHTTPResult;
/**
* Implements HTTP Signatures per draft-cavage-http-signatures-07.
$content_length = strlen($content);
$date = DateTimeFormat::utcNow(DateTimeFormat::HTTP);
- $headers = ['Date: ' . $date, 'Content-Length: ' . $content_length, 'Digest: ' . $digest, 'Host: ' . $host];
+ $headers = [
+ 'Date' => $date,
+ 'Content-Length' => $content_length,
+ 'Digest' => $digest,
+ 'Host' => $host
+ ];
$signed_data = "(request-target): post " . $path . "\ndate: ". $date . "\ncontent-length: " . $content_length . "\ndigest: " . $digest . "\nhost: " . $host;
$signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256'));
- $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) date content-length digest host",signature="' . $signature . '"';
+ $headers['Signature'] = 'keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) date content-length digest host",signature="' . $signature . '"';
- $headers[] = 'Content-Type: application/activity+json';
+ $headers['Content-Type'] = 'application/activity+json';
$postResult = DI::httpRequest()->post($target, $content, $headers);
$return_code = $postResult->getReturnCode();
* 'nobody' => only return the header
* 'cookiejar' => path to cookie jar file
*
- * @return CurlResult CurlResult
+ * @return IHTTPResult CurlResult
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function fetchRaw($request, $uid = 0, $opts = ['accept_content' => 'application/activity+json, application/ld+json'])
+ public static function fetchRaw($request, $uid = 0, $opts = ['accept_content' => ['application/activity+json', 'application/ld+json']])
{
$header = [];
$path = parse_url($request, PHP_URL_PATH);
$date = DateTimeFormat::utcNow(DateTimeFormat::HTTP);
- $header = ['Date: ' . $date, 'Host: ' . $host];
+ $header['Date'] = $date;
+ $header['Host'] = $host;
$signed_data = "(request-target): get " . $path . "\ndate: ". $date . "\nhost: " . $host;
$signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256'));
- $header[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) date host",signature="' . $signature . '"';
- }
-
- if (!empty($opts['accept_content'])) {
- $header[] = 'Accept: ' . $opts['accept_content'];
+ $header['Signature'] = 'keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) date host",signature="' . $signature . '"';
}
$curl_opts = $opts;
$hmac_sig = hash_hmac("sha1", $params, $subscriber['secret']);
- $headers = ["Content-type: application/atom+xml",
- sprintf("Link: <%s>;rel=hub,<%s>;rel=self",
+ $headers = [
+ 'Content-type' => 'application/atom+xml',
+ 'Link' => sprintf("<%s>;rel=hub,<%s>;rel=self",
DI::baseUrl() . '/pubsubhubbub/' . $subscriber['nickname'],
$subscriber['topic']),
- "X-Hub-Signature: sha1=" . $hmac_sig];
+ 'X-Hub-Signature' => 'sha1=' . $hmac_sig];
Logger::log('POST ' . print_r($headers, true) . "\n" . $params, Logger::DATA);