diff --git a/src/Runtime/Octane/OctaneRequestContextFactory.php b/src/Runtime/Octane/OctaneRequestContextFactory.php index 41dae6e..4cdb1ca 100644 --- a/src/Runtime/Octane/OctaneRequestContextFactory.php +++ b/src/Runtime/Octane/OctaneRequestContextFactory.php @@ -38,7 +38,7 @@ public static function fromEvent($event, $serverVariables) $request->serverVariables ); - $serverRequest = $serverRequest->withCookieParams(static::cookies($request->headers)); + $serverRequest = $serverRequest->withCookieParams(static::cookies($event, $request->headers)); $serverRequest = $serverRequest->withUploadedFiles(static::uploadedFiles( $method, $contentType, $request->body @@ -60,18 +60,25 @@ public static function fromEvent($event, $serverVariables) /** * Get the cookies from the given headers. * + * @param array $event * @param array $headers * @return array */ - protected static function cookies($headers) + protected static function cookies($event, $headers) { - $headers = array_change_key_case($headers); + if (isset($event['version']) && $event['version'] === '2.0') { + $cookies = $event['cookies'] ?? []; + } else { + $headers = array_change_key_case($headers); + + $cookies = isset($headers['cookie']) ? explode('; ', $headers['cookie']) : []; + } - if (! isset($headers['cookie']) || empty($headers['cookie'])) { + if (empty($cookies)) { return []; } - return Collection::make(explode('; ', $headers['cookie']))->mapWithKeys(function ($cookie) { + return Collection::make($cookies)->mapWithKeys(function ($cookie) { $cookie = explode('=', trim($cookie), 2); $key = $cookie[0]; diff --git a/tests/Feature/LambdaProxyOctaneHandlerTest.php b/tests/Feature/LambdaProxyOctaneHandlerTest.php index 7a69cb5..e3a1f64 100644 --- a/tests/Feature/LambdaProxyOctaneHandlerTest.php +++ b/tests/Feature/LambdaProxyOctaneHandlerTest.php @@ -396,8 +396,8 @@ public function test_request_cookies() 'path' => '/', ], ], - 'headers' => [ - 'cookie' => 'XSRF-TOKEN=token_value', + 'cookies' => [ + 'XSRF-TOKEN=token_value', ], ]); @@ -423,8 +423,9 @@ public function test_request_ignores_invalid_cookies() 'path' => '/', ], ], - 'headers' => [ - 'cookie' => 'cookieKey1; cookieKey2=cookieValue2', + 'cookies' => [ + 'cookieKey1', + 'cookieKey2=cookieValue2', ], ]);