From 3987cad9b738b8ffd28a01f46bd7370c589b2917 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 2 Jul 2016 13:44:25 +0200 Subject: [PATCH] Use delivered content-type to parse XML_XRD In issue #205 we saw data coming in with an additional line-break before the JSON data which fuzzed the auto-detection in XML_XRD (which assumed a { as the first character). If we use the Content-type header from HTTP we can avoid that issue. --- plugins/LRDD/lib/discovery.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/LRDD/lib/discovery.php b/plugins/LRDD/lib/discovery.php index 579f414bc6..03f24e04fa 100644 --- a/plugins/LRDD/lib/discovery.php +++ b/plugins/LRDD/lib/discovery.php @@ -122,8 +122,22 @@ class Discovery throw new Exception('Unexpected HTTP status code.'); } - $xrd->loadString($response->getBody()); + switch ($response->getHeader('content-type')) { + case self::JRD_MIMETYPE_OLD: + case self::JRD_MIMETYPE: + $type = 'json'; + break; + case self::XRD_MIMETYPE: + $type = 'xml'; + break; + default: + // fall back to letting XML_XRD auto-detect + common_debug('No recognized content-type header for resource descriptor body.'); + $type = null; + } + $xrd->loadString($response->getBody(), $type); return $xrd; + } catch (Exception $e) { common_log(LOG_INFO, sprintf('%s: Failed for %s: %s', _ve($class), _ve($uri), _ve($e->getMessage()))); continue; -- 2.39.5