-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rest): extend REST request to allow OPTIONS without error (#55)
Co-authored-by: Evan Johnson <[email protected]>
- Loading branch information
1 parent
7efabca
commit eb1df2d
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright 2017 SplashLab | ||
*/ | ||
/** | ||
* Copyright © Graycore, LLC. All rights reserved. | ||
* See LICENSE.md for details. | ||
*/ | ||
|
||
namespace Graycore\Cors\Request; | ||
|
||
use Magento\Framework\Webapi\Request; | ||
use Magento\Framework\Exception\InputException; | ||
|
||
class RestRequest | ||
{ | ||
/** | ||
* Triggers before original dispatch | ||
* | ||
* @param Request $subject | ||
* @return void | ||
* @throws InputException | ||
*/ | ||
public function aroundGetHttpMethod( | ||
Request $subject | ||
) { | ||
if (!$subject->isGet() | ||
&& !$subject->isPost() | ||
&& !$subject->isPut() | ||
&& !$subject->isDelete() | ||
&& !$subject->isOptions() | ||
) { | ||
throw new InputException(__('Request method is invalid.')); | ||
} | ||
return $subject->getMethod(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters