]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Use delivered content-type to parse XML_XRD
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 2 Jul 2016 11:44:25 +0000 (13:44 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 2 Jul 2016 11:44:25 +0000 (13:44 +0200)
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

index 579f414bc67fe772ac367df516f65e791a4e7040..03f24e04fa6c88a997ad92bda95c80172b8dfde0 100644 (file)
@@ -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;