From bb34295b8772673294bc77c9f4ce93af57281208 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sun, 27 Aug 2017 22:39:01 +0200 Subject: [PATCH 1/1] Split off content type comments Resolves: https://github.com/cweiske/shpub/pull/6 --- src/shpub/Command/Connect.php | 4 ++-- src/shpub/Command/Targets.php | 2 +- src/shpub/Request.php | 2 +- src/shpub/Util.php | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/shpub/Util.php 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 -- 2.30.2