Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
15ae828
Updated FPM php to cater for api gateways authorisers
pl4yradam Nov 10, 2019
9449c74
Whitespace error
pl4yradam Nov 10, 2019
1dea31e
Tidying up request context to handle no request context
pl4yradam Nov 10, 2019
2e44107
Adding test for request context
pl4yradam Nov 10, 2019
4fe737f
Spaces
AdamKernig Nov 10, 2019
4c6da44
Pretty v89
AdamKernig Nov 10, 2019
3391edb
Detecting if request context exists
AdamKernig Nov 10, 2019
ccd138d
Pretty baby
AdamKernig Nov 10, 2019
4e63216
Update
AdamKernig Nov 10, 2019
eed8487
Updating handeling better
AdamKernig Nov 10, 2019
ce1bca9
)
AdamKernig Nov 10, 2019
fd1859e
Fixing previous test that didn't check for request
AdamKernig Nov 10, 2019
34ffa17
Multiline error
AdamKernig Nov 10, 2019
50fd85f
Update
AdamKernig Nov 11, 2019
9f8d7d1
looping
AdamKernig Nov 11, 2019
9f52b43
Consistant naming
AdamKernig Nov 11, 2019
4628bc6
Fix tests
AdamKernig Nov 11, 2019
59f8c11
Redesigning array
AdamKernig Nov 11, 2019
1792a89
Testing request dump
AdamKernig Nov 11, 2019
0ab40cd
Printr
AdamKernig Nov 11, 2019
2d7e761
testing assoc
AdamKernig Nov 11, 2019
9680466
Update
AdamKernig Nov 11, 2019
7f3ba71
Syntax correction
AdamKernig Nov 11, 2019
4ab0e3f
Syntax correction
AdamKernig Nov 11, 2019
ffbe265
Syntax correction
AdamKernig Nov 11, 2019
5a6902d
Syntax correction
AdamKernig Nov 11, 2019
23c4e48
Syntax correction
AdamKernig Nov 11, 2019
8c68500
Syntax correction
AdamKernig Nov 11, 2019
6caa91e
setCustomVar does not accept arrays
AdamKernig Nov 11, 2019
94b0158
Exp
AdamKernig Nov 11, 2019
8fdbcdc
test
AdamKernig Nov 11, 2019
391cdc5
test
AdamKernig Nov 11, 2019
e10af91
test
AdamKernig Nov 11, 2019
c76ad0e
test
AdamKernig Nov 11, 2019
c2d0706
test
AdamKernig Nov 11, 2019
7e180ed
test
AdamKernig Nov 11, 2019
4a2d8cf
test
AdamKernig Nov 11, 2019
796c1eb
test
AdamKernig Nov 11, 2019
b641f5f
test
AdamKernig Nov 11, 2019
1f4b8df
test
AdamKernig Nov 11, 2019
59ab4f1
test
AdamKernig Nov 11, 2019
06880df
test
AdamKernig Nov 11, 2019
958fa0c
test
AdamKernig Nov 11, 2019
cb5666d
test
AdamKernig Nov 11, 2019
864e78e
Final
AdamKernig Nov 11, 2019
3a81e38
Change to array
AdamKernig Nov 12, 2019
697b928
Fast cgi does not support arrarys
AdamKernig Nov 12, 2019
ec917cd
Adding in recursive behaviour
AdamKernig Nov 12, 2019
20f31d6
Visciously attacked by pretty
AdamKernig Nov 12, 2019
f411743
Revenge of the pretty
AdamKernig Nov 12, 2019
0f52430
Im coming for you pretty
AdamKernig Nov 12, 2019
518bf6b
Pretty, we meet again
AdamKernig Nov 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/Runtime/PhpFpm.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private function isReady(): bool
private function eventToFastCgiRequest(array $event): ProvidesRequestData
{
$requestBody = $event['body'] ?? '';

if ($event['isBase64Encoded'] ?? false) {
$requestBody = base64_decode($requestBody);
}
Expand Down Expand Up @@ -209,7 +210,9 @@ private function eventToFastCgiRequest(array $event): ProvidesRequestData
$request->setServerPort((int) ($headers['x-forwarded-port'][0] ?? 80));
$request->setCustomVar('PATH_INFO', $event['path'] ?? '/');
$request->setCustomVar('QUERY_STRING', $queryString);

if ($event['requestContext'] ?? false) {
$this->setArrayValue('REQUEST_CONTEXT', $event['requestContext'], $request);
}
// See https://stackoverflow.com/a/5519834/245552
if (! empty($requestBody) && $method !== 'TRACE' && ! isset($headers['content-type'])) {
$headers['content-type'] = ['application/x-www-form-urlencoded'];
Expand Down Expand Up @@ -355,4 +358,24 @@ private function getResponseHeaders(ProvidesResponseData $response, bool $isMult

return array_change_key_case($responseHeaders, CASE_LOWER);
}

/**
* Recursively loop through a data object and create env variables
*/
private function setArrayValue(string $name, array $array, FastCgiRequest $request): void
{
if (! is_array($array)) {
$request->setCustomVar(strtoupper($name), $array);
}

foreach ($array as $key => $value) {
if (! is_array($value)) {
$request->setCustomVar(strtoupper($name . '_' . $key), $value);
}

if (is_array($value)) {
$this->setArrayValue(strtoupper($name . '_' . $key), $value, $request);
}
}
}
}
51 changes: 51 additions & 0 deletions tests/Runtime/PhpFpmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function test simple request()
'QUERY_STRING' => '',
'CONTENT_LENGTH' => '0',
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
'REQUEST_CONTEXT_PROTOCOL' => 'HTTP/1.1',
],
'HTTP_RAW_BODY' => '',
]);
Expand Down Expand Up @@ -118,6 +119,56 @@ public function test request with multivalues query string have basic su
]);
}

public function test request with requestContext array support()
{
$event = [
'httpMethod' => 'GET',
'path' => '/hello',
// See https://aws.amazon.com/blogs/compute/support-for-multi-value-parameters-in-amazon-api-gateway/
'multiValueQueryStringParameters' => [
'foo' => ['bar', 'baz'],
],
'queryStringParameters' => [
'foo' => 'baz', // the 2nd value is preserved only by API Gateway
],
'requestContext' => [
'foo' => 'baz',
'baz' => 'far',
'data' => [
'recurse1' => 1,
'recurse2' => 2,
],
],
];
$this->assertGlobalVariables($event, [
'$_GET' => [
// TODO The feature is not implemented yet
'foo' => 'bar',
],
'$_POST' => [],
'$_FILES' => [],
'$_COOKIE' => [],
'$_REQUEST' => [
'foo' => 'bar',
],
'$_SERVER' => [
'REQUEST_URI' => '/hello?foo=bar',
'PHP_SELF' => '/hello',
'PATH_INFO' => '/hello',
'REQUEST_METHOD' => 'GET',
'QUERY_STRING' => 'foo=bar',
'CONTENT_LENGTH' => '0',
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
'REQUEST_CONTEXT_FOO' => 'baz',
'REQUEST_CONTEXT_BAZ' => 'far',
'REQUEST_CONTEXT_DATA_RECURSE1' => 1,
'REQUEST_CONTEXT_DATA_RECURSE2' => 2,
],
'HTTP_RAW_BODY' => '',

]);
}

public function test request with arrays in query string()
{
$event = [
Expand Down