From 4cab09d5e93346cb95e7ac9391b8a6da959a81b4 Mon Sep 17 00:00:00 2001 From: Gabriel Peixoto Date: Wed, 29 Mar 2023 13:42:09 -0300 Subject: [PATCH] Change get body to works with Octane --- src/SNSController.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/SNSController.php b/src/SNSController.php index 2869172..be2f23c 100644 --- a/src/SNSController.php +++ b/src/SNSController.php @@ -27,7 +27,7 @@ public function callback(Request $request) // for SNSMessage we have to pass the json data in $request->message $message = new SNSMessage(json_decode($request->message, true)); } else { - $message = SNSMessage::fromRawPostData(); + $message = $this->fromJsonString($request); $validator = app(SNSMessageValidator::class); $validator->validate($message); } @@ -44,6 +44,23 @@ public function callback(Request $request) } } + /** + * @param \Illuminate\Http\Request $request + * @return \Aws\Sns\Message + */ + private function fromJsonString(Request $request) + { + // get body from request + $body = $request->getContent(); + + // Make sure the SNS-provided header exists. + if (!isset($_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE'])) { + throw new \RuntimeException('SNS message type header not provided.'); + } + + return SNSMessage::fromJsonString($body); + } + protected function confirm_subscription($message) { $client = new Guzzle();