kopia lustrzana https://github.com/nextcloud/social
Merge pull request #290 from nextcloud/bugfix/269/better-parsing-of-accept-header
compare Accept Header from a listpull/273/head
commit
08aaf48c1a
|
@ -316,27 +316,34 @@ class ActivityPubController extends Controller {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function checkSourceActivityStreams(): bool {
|
private function checkSourceActivityStreams(): bool {
|
||||||
|
$accepted = [
|
||||||
|
'application/ld+json',
|
||||||
|
'application/activity+json'
|
||||||
|
];
|
||||||
|
|
||||||
// uncomment this line to display the result that would be return to an ActivityPub service (TEST)
|
$accepts = explode(',', $this->request->getHeader('Accept'));
|
||||||
// return true;
|
$accepts = array_map([$this, 'trimHeader'], $accepts);
|
||||||
|
|
||||||
// TODO - cleaner to being able to parse:
|
foreach ($accepts as $accept) {
|
||||||
// - 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
|
if (in_array($accept, $accepted)) {
|
||||||
// - 'application/activity+json, application/ld+json'
|
|
||||||
$accept = explode(',', $this->request->getHeader('Accept'));
|
|
||||||
$accept = array_map('trim', $accept);
|
|
||||||
|
|
||||||
if (in_array('application/ld+json', $accept)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->getHeader('Accept')
|
|
||||||
=== 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"') {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function trimHeader(string $header) {
|
||||||
|
$header = trim($header);
|
||||||
|
|
||||||
|
$pos = strpos($header, ';');
|
||||||
|
if ($pos === false) {
|
||||||
|
return $header;
|
||||||
|
}
|
||||||
|
|
||||||
|
return substr($header, 0, $pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue