mirror of
https://github.com/friendica/friendica
synced 2025-04-30 09:04:22 +02:00
Fixup HTTP headers for httpClient requests
This commit is contained in:
parent
c7f54d83ce
commit
2356221aba
12 changed files with 36 additions and 33 deletions
|
@ -29,6 +29,7 @@ use Friendica\Model\APContact;
|
|||
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.
|
||||
|
@ -290,15 +291,20 @@ class HTTPSignature
|
|||
$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();
|
||||
|
@ -409,10 +415,10 @@ class HTTPSignature
|
|||
* '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 = [];
|
||||
|
||||
|
@ -434,17 +440,14 @@ class HTTPSignature
|
|||
$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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue