From c9d84043220fd7b87515578a360cbddb6f0f112f Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Mon, 3 Apr 2023 22:15:04 +0200 Subject: [PATCH] Fix case with the string "null" being sent back when using streaming --- ChangeLog.md | 5 +++++ .../php/com/amazon/aws/lambda/ResponseDocument.class.php | 6 +++++- .../com/amazon/aws/lambda/unittest/HttpApiTest.class.php | 1 - .../aws/lambda/unittest/ResponseDocumentTest.class.php | 1 - 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 8d08a7a..849b924 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,11 @@ AWS Lambda Webservices change log ## ?.?.? / ????-??-?? +## 1.1.4 / 2023-04-03 + +* Fixed case with the string "null" being sent back when using streaming + and never writing to the response stream by removing response `body` + (@thekid) * Merged PR #9: Migrate to new testing library - @thekid ## 1.1.3 / 2022-10-14 diff --git a/src/main/php/com/amazon/aws/lambda/ResponseDocument.class.php b/src/main/php/com/amazon/aws/lambda/ResponseDocument.class.php index cd160a3..93b8ac9 100755 --- a/src/main/php/com/amazon/aws/lambda/ResponseDocument.class.php +++ b/src/main/php/com/amazon/aws/lambda/ResponseDocument.class.php @@ -6,6 +6,7 @@ * Response document * * @test com.amazon.aws.lambda.unittest.ResponseDocumentTest + * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html */ class ResponseDocument extends Output { public $document; @@ -97,7 +98,10 @@ public function write($bytes) { /** @return void */ public function finish() { - if (null === $this->document['body']) return; + if (null === $this->document['body']) { + unset($this->document['body']); + return; + } // Report unencoded length in headers $this->document['headers']['Content-Length']= (string)strlen($this->document['body']); diff --git a/src/test/php/com/amazon/aws/lambda/unittest/HttpApiTest.class.php b/src/test/php/com/amazon/aws/lambda/unittest/HttpApiTest.class.php index 5052644..259ad4d 100755 --- a/src/test/php/com/amazon/aws/lambda/unittest/HttpApiTest.class.php +++ b/src/test/php/com/amazon/aws/lambda/unittest/HttpApiTest.class.php @@ -127,7 +127,6 @@ public function routes($env) { 'statusDescription' => 'Found', 'isBase64Encoded' => false, 'headers' => ['Location' => 'https://example.com', 'Content-Length' => 0], - 'body' => null, ], $this->invoke($fixture->target(), 'GET') ); diff --git a/src/test/php/com/amazon/aws/lambda/unittest/ResponseDocumentTest.class.php b/src/test/php/com/amazon/aws/lambda/unittest/ResponseDocumentTest.class.php index 9892d01..fb06039 100755 --- a/src/test/php/com/amazon/aws/lambda/unittest/ResponseDocumentTest.class.php +++ b/src/test/php/com/amazon/aws/lambda/unittest/ResponseDocumentTest.class.php @@ -23,7 +23,6 @@ public function no_content() { 'statusDescription' => 'No Content', 'isBase64Encoded' => false, 'headers' => [], - 'body' => null, ], $out->document );