Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Bootstrap edits #25

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
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
22 changes: 4 additions & 18 deletions bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,7 @@ while (true) {
$uri = $event['path'];

if (array_key_exists('multiValueQueryStringParameters', $event) && $event['multiValueQueryStringParameters']) {
$first = TRUE;
foreach ($event['multiValueQueryStringParameters'] as $name => $values) {
foreach ($values as $value) {
if ($first) {
$uri .= "?";
$first = FALSE;
} else {
$uri .= "&";
}

$uri .= $name;

if ($value != '') {
$uri .= '=' . $value;
}
}
}
$uri .= "?" . http_build_query($event['multiValueQueryStringParameters']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this really does the right thing. For example, multiValueQueryStringParameters might have the following value:

    "multiValueQueryStringParameters":{
      "name":[
        "me"
      ],
      "multivalueName":[
        "you",
        "me"
      ]
    }

This corresponds to a url querystring like ?name=me&multivalueName=you&multivalueName=me

If you fed the same data into http_build_query, it would generate the following querystring: ?name[0]=me&multivalueName[0]=you&multivalueName[1]=me. (The square brackets [] would actually be url-encoded, but I left them unencoded to make it easier to understand here.)

Can you double check my thinking?

Copy link

@jaimz22 jaimz22 Jan 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@txase php requires the square brackets to exist for multiple value query string parameters.

if php parses the query string ?name=me&multivalueName=you&multivalueName=me you'll end up with:

array(2) { ["multivalueName"]=> string(2) "me" ["name"]=> string(2) "me" } 

when you have the square brackets you receive the full array in php:

array(2) { ["multivalueName"]=> array(2) { [0]=> string(3) "you" [1]=> string(2) "me" } ["name"]=> string(2) "me" } 

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be that PHP requires square brackets to exist for multiple value query string parameters, but this layer proxies parameters as they were received by API Gateway from the client. If they aren't in the correct format for PHP to understand them, then the client needs to be fixed to send them correctly.

I don't want to modify requests as they are received and then proxied to and from the PHP webserver.

}

$ch = curl_init("http://localhost:8000$uri");
Expand Down Expand Up @@ -161,7 +145,7 @@ while (true) {
if (strlen($body) > 0) {
if($event['httpMethod'] === 'POST'){
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
}
}
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($body));
curl_setopt($ch, CURLOPT_READFUNCTION, function ($ch, $fd, $length) use ($body) {
return $body;
Expand Down Expand Up @@ -191,6 +175,8 @@ while (true) {
return strlen($header);
}

$name = strtolower($name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not lose the fidelity of the header name as it passes through the layer. If the API Gateway or ALB can pass it with a specific case, let's leave it as-is.


if (!array_key_exists($name, $response['multiValueHeaders'])) {
$response['multiValueHeaders'][$name] = array();
}
Expand Down