From 9aca9ca6e4895d4bf0e1838e2ededea4dbc3b41c Mon Sep 17 00:00:00 2001 From: Pablo Date: Tue, 13 Jan 2015 14:33:09 -0600 Subject: [PATCH] Default Accept header. According to the documentation http://devdocs.magento.com/guides/v1.0/get-started/gs-web-api-request.html#http-headers json should be the default for Accept header but if you don't send the Accept header at all an error is thrown saying "Server cannot understand Accept HTTP header media type.", this commit intention is to make application/json the default Accept for REST requests. --- app/code/Magento/Webapi/Controller/Rest/Request.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Webapi/Controller/Rest/Request.php b/app/code/Magento/Webapi/Controller/Rest/Request.php index 1c0bd7ec90357..6529724cc77c8 100644 --- a/app/code/Magento/Webapi/Controller/Rest/Request.php +++ b/app/code/Magento/Webapi/Controller/Rest/Request.php @@ -75,7 +75,14 @@ public function getAcceptTypes() $qualityToTypes = []; $orderedTypes = []; - foreach (preg_split('/,\s*/', $this->getHeader('Accept')) as $definition) { + $headerAccept = $this->getHeader('Accept'); + $defaultAccept = \Magento\Webapi\Controller\Rest\Response\Renderer\Json::MIME_TYPE; + + if(false === $headerAccept) { + $headerAccept = $defaultAccept; + } + + foreach (preg_split('/,\s*/', $headerAccept) as $definition) { $typeWithQ = explode(';', $definition); $mimeType = trim(array_shift($typeWithQ));