From: Mikael Nordfeldth Date: Sat, 2 Jul 2016 11:44:25 +0000 (+0200) Subject: Use delivered content-type to parse XML_XRD X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3987cad9b738b8ffd28a01f46bd7370c589b2917;p=quix0rs-gnu-social.git 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. --- 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;