Merge pull request #14422 from annando/issue-14370
Issue 14370: Improved content negogiationpull/14423/head
commit
c8dbafad83
|
@ -34,22 +34,14 @@ class Xrd extends BaseModule
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = urldecode(trim($_GET['uri']));
|
$uri = urldecode(trim($_GET['uri']));
|
||||||
if (strpos($_SERVER['HTTP_ACCEPT'] ?? '', 'application/jrd+json') !== false) {
|
$mode = self::getAcceptedContentType($_SERVER['HTTP_ACCEPT'] ?? '', Response::TYPE_JSON);
|
||||||
$mode = Response::TYPE_JSON;
|
|
||||||
} else {
|
|
||||||
$mode = Response::TYPE_XML;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (empty($_GET['resource'])) {
|
if (empty($_GET['resource'])) {
|
||||||
throw new BadRequestException();
|
throw new BadRequestException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = urldecode(trim($_GET['resource']));
|
$uri = urldecode(trim($_GET['resource']));
|
||||||
if (strpos($_SERVER['HTTP_ACCEPT'] ?? '', 'application/xrd+xml') !== false) {
|
$mode = self::getAcceptedContentType($_SERVER['HTTP_ACCEPT'] ?? '', Response::TYPE_XML);
|
||||||
$mode = Response::TYPE_XML;
|
|
||||||
} else {
|
|
||||||
$mode = Response::TYPE_JSON;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (substr($uri, 0, 4) === 'http') {
|
if (substr($uri, 0, 4) === 'http') {
|
||||||
|
@ -102,6 +94,36 @@ class Xrd extends BaseModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect the accepted content type.
|
||||||
|
* @todo Handle priorities (see "application/xrd+xml,text/xml;q=0.9")
|
||||||
|
*
|
||||||
|
* @param string $accept
|
||||||
|
* @param string $default
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getAcceptedContentType(string $accept, string $default): string
|
||||||
|
{
|
||||||
|
$parts = [];
|
||||||
|
foreach (explode(',', $accept) as $part) {
|
||||||
|
$parts[] = current(explode(';', $part));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($parts)) {
|
||||||
|
return $default;
|
||||||
|
} elseif (in_array('application/jrd+json', $parts) && !in_array('application/xrd+xml', $parts)) {
|
||||||
|
return Response::TYPE_JSON;
|
||||||
|
} elseif (!in_array('application/jrd+json', $parts) && in_array('application/xrd+xml', $parts)) {
|
||||||
|
return Response::TYPE_XML;
|
||||||
|
} elseif (in_array('application/json', $parts) && !in_array('text/xml', $parts)) {
|
||||||
|
return Response::TYPE_JSON;
|
||||||
|
} elseif (!in_array('application/json', $parts) && in_array('text/xml', $parts)) {
|
||||||
|
return Response::TYPE_XML;
|
||||||
|
} else {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function printSystemJSON(array $owner)
|
private function printSystemJSON(array $owner)
|
||||||
{
|
{
|
||||||
$baseURL = (string)$this->baseUrl;
|
$baseURL = (string)$this->baseUrl;
|
||||||
|
|
Loading…
Reference in New Issue