forked from GNUsocial/gnu-social
		
	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.
This commit is contained in:
		| @@ -122,8 +122,22 @@ class Discovery | |||||||
|                     throw new Exception('Unexpected HTTP status code.'); |                     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; |                 return $xrd; | ||||||
|  |  | ||||||
|             } catch (Exception $e) { |             } catch (Exception $e) { | ||||||
|                 common_log(LOG_INFO, sprintf('%s: Failed for %s: %s', _ve($class), _ve($uri), _ve($e->getMessage()))); |                 common_log(LOG_INFO, sprintf('%s: Failed for %s: %s', _ve($class), _ve($uri), _ve($e->getMessage()))); | ||||||
|                 continue; |                 continue; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user