From: Christian Weiske Date: Sun, 27 Aug 2017 20:39:01 +0000 (+0200) Subject: Split off content type comments X-Git-Tag: v0.5.0~5 X-Git-Url: https://git.cweiske.de/shpub.git/commitdiff_plain/bb34295b8772673294bc77c9f4ce93af57281208 Split off content type comments Resolves: https://github.com/cweiske/shpub/pull/6 --- diff --git a/src/shpub/Command/Connect.php b/src/shpub/Command/Connect.php index c855e66..e920777 100644 --- a/src/shpub/Command/Connect.php +++ b/src/shpub/Command/Connect.php @@ -158,9 +158,9 @@ class Command_Connect 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'); diff --git a/src/shpub/Command/Targets.php b/src/shpub/Command/Targets.php index eb66692..8d76e77 100644 --- a/src/shpub/Command/Targets.php +++ b/src/shpub/Command/Targets.php @@ -29,7 +29,7 @@ class Command_Targets $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); } diff --git a/src/shpub/Request.php b/src/shpub/Request.php index 3d7221d..dce163f 100644 --- a/src/shpub/Request.php +++ b/src/shpub/Request.php @@ -108,7 +108,7 @@ class Request ); $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'); diff --git a/src/shpub/Util.php b/src/shpub/Util.php new file mode 100644 index 0000000..d0df03f --- /dev/null +++ b/src/shpub/Util.php @@ -0,0 +1,18 @@ +getHeader('content-type')); + return trim($type); + } +} \ No newline at end of file