Log::err($res->getBody());
exit(2);
}
- if ($res->getHeader('content-type') == 'application/x-www-form-urlencoded') {
+ if (Util::getMimeType($res) == 'application/x-www-form-urlencoded') {
parse_str($res->getBody(), $tokenParams);
- } elseif ($res->getHeader('content-type') == 'application/json') {
+ } elseif (Util::getMimeType($res) == 'application/json') {
$tokenParams = json_decode($res->getBody(), true);
} else {
Log::err('Wrong content type in auth verification response');
$req->req->getUrl()->setQueryVariable('q', 'syndicate-to');
$res = $req->send();
- if ($res->getHeader('content-type') != 'application/json') {
+ if (Util::getMimeType($res) != 'application/json') {
Log::err('response data are not of type application/json');
exit(2);
}
);
$shown = false;
- if ($res->getHeader('content-type') == 'application/json') {
+ if (Util::getMimeType($res) == 'application/json') {
$errData = json_decode($res->getBody());
if (!isset($errData->error)) {
Log::err('Error response does not contain "error" property');
--- /dev/null
+<?php
+namespace shpub;
+
+class Util
+{
+ /**
+ * Get the MIME content type from a HTTP response
+ *
+ * @param object $res HTTP response
+ *
+ * @return string MIME type without comments
+ */
+ public static function getMimeType(\HTTP_Request2_Response $res)
+ {
+ list($type, ) = explode(';', $res->getHeader('content-type'));
+ return trim($type);
+ }
+}
\ No newline at end of file