Skip to content

Commit d43faf4

Browse files
dmerchierNyholm
andauthored
[Bref] Add invocation and request context to the Request ServerBag (#78)
* Add invocation and request context to the Request ServerBag * Added tests Co-authored-by: Nyholm <[email protected]>
1 parent 8108bfc commit d43faf4

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}
1111
],
1212
"require": {
13+
"ext-json": "*",
1314
"bref/bref": "^1.2",
1415
"clue/arguments": "^2.1",
1516
"psr/http-server-handler": "^1.0",

src/SymfonyRequestBridge.php

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public static function convertRequest(HttpRequestEvent $event, Context $context)
3838
'REQUEST_TIME_FLOAT' => microtime(true),
3939
'REQUEST_URI' => $event->getUri(),
4040
'REMOTE_ADDR' => '127.0.0.1',
41+
'LAMBDA_INVOCATION_CONTEXT' => json_encode($context),
42+
'LAMBDA_REQUEST_CONTEXT' => json_encode($event->getRequestContext()),
4143
], fn ($value) => null !== $value);
4244

4345
foreach ($event->getHeaders() as $name => $values) {

tests/SymfonyRequestBridgeTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ public function testEmptyUploadedFile()
135135
$this->assertSame('bar', $post['foo']);
136136
}
137137

138+
public function testLambdaContext()
139+
{
140+
$requestContext = ['http' => ['method' => 'GET']];
141+
$request = SymfonyRequestBridge::convertRequest(new HttpRequestEvent([
142+
'requestContext' => $requestContext,
143+
]), $invocationContext = $this->getContext());
144+
$this->assertTrue($request->server->has('LAMBDA_INVOCATION_CONTEXT'));
145+
$this->assertTrue($request->server->has('LAMBDA_REQUEST_CONTEXT'));
146+
147+
$this->assertSame(json_encode($invocationContext), $request->server->get('LAMBDA_INVOCATION_CONTEXT'));
148+
$this->assertSame(json_encode($requestContext), $request->server->get('LAMBDA_REQUEST_CONTEXT'));
149+
}
150+
138151
private function getContext()
139152
{
140153
return new Context('id', 1000, 'function', 'trace');

0 commit comments

Comments
 (0)