Skip to content

Commit 1c98bd8

Browse files
committed
MAGETWO-32767: [GITHUB] #963
- Added default accept if no Accept header passed - Added api functional tests
1 parent d33f01d commit 1c98bd8

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

app/code/Magento/Webapi/Controller/Rest/Request.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class Request extends \Magento\Webapi\Controller\Request
1818
*/
1919
const REQUEST_CHARSET = 'utf-8';
2020

21+
const DEFAULT_ACCEPT = '*/*';
22+
2123
/** @var string */
2224
protected $_serviceName;
2325

@@ -101,7 +103,7 @@ public function getAcceptTypes()
101103
foreach ($qualityToTypes as $typeList) {
102104
$orderedTypes += $typeList;
103105
}
104-
return array_keys($orderedTypes);
106+
return empty($orderedTypes) ? self::DEFAULT_ACCEPT : array_keys($orderedTypes);
105107
}
106108

107109
/**

dev/tests/api-functional/_files/Magento/TestModule1/etc/webapi.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
<resource ref="Magento_TestModule1::resource2" />
5353
</resources>
5454
</route>
55+
<route method="GET" url="/V1/testmodule1/resource1/:itemId">
56+
<service class="Magento\TestModule1\Service\V1\AllSoapAndRestInterface" method="item" />
57+
<resources>
58+
<resource ref="anonymous" />
59+
</resources>
60+
</route>
5561
<route method="POST" url="/V1/testmodule1/itemAnyType">
5662
<service class="Magento\TestModule1\Service\V1\AllSoapAndRestInterface" method="itemAnyType" />
5763
<resources>

dev/tests/api-functional/testsuite/Magento/Webapi/Routing/CoreRoutingTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
*/
1010
namespace Magento\Webapi\Routing;
1111

12+
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use Magento\TestFramework\TestCase\Webapi\Adapter\Rest\CurlClient;
15+
1216
class CoreRoutingTest extends \Magento\Webapi\Routing\BaseService
1317
{
1418
public function testBasicRoutingExplicitPath()
@@ -73,4 +77,15 @@ public function testExceptionSoapInternalError()
7377
$this->setExpectedException('SoapFault', 'Generic service exception');
7478
$this->_webApiCall($serviceInfo);
7579
}
80+
81+
public function testRestNoAcceptHeader()
82+
{
83+
$this->_markTestAsRestOnly();
84+
/** @var $curlClient CurlClient */
85+
$curlClient = Bootstrap::getObjectManager()->get(
86+
'Magento\TestFramework\TestCase\Webapi\Adapter\Rest\CurlClient'
87+
);
88+
$response = $curlClient->get('/V1/testmodule1/resource1/1', [], ['Accept:']);
89+
$this->assertEquals('testProduct1', $response['name'], "Empty Accept header failed to return response.");
90+
}
7691
}

0 commit comments

Comments
 (0)