jdecool/scaleway-runtimepublic Fork
⑂ 581465d
Commits
⬇ Clone ▾
git clone https://git.rickub.com/jdecool/scaleway-runtime.git
git clone ssh://git@rickub.com/jdecool/scaleway-runtime.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

fix: isolate Function Responses from leftover output buffers and arg_separator.outputUnverified

A streamed Response leaving a buffer open lost its body and swallowed the
output of later Invocations, and one closing every buffer triggered a notice.
The query string is now always built with "&".
Jérémy DECOOL committed 2026-11-13T22:05:31+01:00 Browse files
581465d parent: d541338
modified src/HttpConverter.php +8 -2
@@ -32,7 +32,8 @@ final class HttpConverter
3232 {
3333 $method = strtoupper(self::string($event['method'] ?? $event['httpMethod'] ?? null) ?? 'GET');
3434 $path = '/'.ltrim(self::string($event['path'] ?? null) ?? '', '/');
35- $queryString = http_build_query(self::stringMap($event['queryStringParameters'] ?? null));
35+ // An explicit separator, as arg_separator.output may be "&".
36+ $queryString = http_build_query(self::stringMap($event['queryStringParameters'] ?? null), '', '&');
3637 parse_str($queryString, $query);
3738
3839 $body = self::string($event['body'] ?? null) ?? '';
@@ -82,6 +83,7 @@ final class HttpConverter
8283 public static function toFunctionResponse(Response $response): array
8384 {
8485 $body = '';
86+ $level = ob_get_level();
8587 // A callback handler keeps the chunks even when a streamed callback calls ob_flush().
8688 ob_start(static function (string $chunk) use (&$body): string {
8789 $body .= $chunk;
@@ -91,7 +93,11 @@ final class HttpConverter
9193 try {
9294 $response->sendContent();
9395 } finally {
94- ob_end_flush();
96+ // Buffers the Application left open would swallow the output of later Invocations,
97+ // and ours may already be gone if it closed every buffer.
98+ while (ob_get_level() > $level) {
99+ ob_end_flush();
100+ }
95101 }
96102
97103 $values = $response->headers->allPreserveCaseWithoutCookies();
@@ -32,7 +32,8 @@ final class HttpConverter
32 {32 {
33 $method = strtoupper(self::string($event['method'] ?? $event['httpMethod'] ?? null) ?? 'GET');33 $method = strtoupper(self::string($event['method'] ?? $event['httpMethod'] ?? null) ?? 'GET');
34 $path = '/'.ltrim(self::string($event['path'] ?? null) ?? '', '/');34 $path = '/'.ltrim(self::string($event['path'] ?? null) ?? '', '/');
35- $queryString = http_build_query(self::stringMap($event['queryStringParameters'] ?? null));35+ // An explicit separator, as arg_separator.output may be "&".
36+ $queryString = http_build_query(self::stringMap($event['queryStringParameters'] ?? null), '', '&');
36 parse_str($queryString, $query);37 parse_str($queryString, $query);
37 38
38 $body = self::string($event['body'] ?? null) ?? '';39 $body = self::string($event['body'] ?? null) ?? '';
@@ -82,6 +83,7 @@ final class HttpConverter
82 public static function toFunctionResponse(Response $response): array83 public static function toFunctionResponse(Response $response): array
83 {84 {
84 $body = '';85 $body = '';
86+ $level = ob_get_level();
85 // A callback handler keeps the chunks even when a streamed callback calls ob_flush().87 // A callback handler keeps the chunks even when a streamed callback calls ob_flush().
86 ob_start(static function (string $chunk) use (&$body): string {88 ob_start(static function (string $chunk) use (&$body): string {
87 $body .= $chunk;89 $body .= $chunk;
@@ -91,7 +93,11 @@ final class HttpConverter
91 try {93 try {
92 $response->sendContent();94 $response->sendContent();
93 } finally {95 } finally {
94- ob_end_flush();96+ // Buffers the Application left open would swallow the output of later Invocations,
97+ // and ours may already be gone if it closed every buffer.
98+ while (ob_get_level() > $level) {
99+ ob_end_flush();
100+ }
95 }101 }
96 102
97 $values = $response->headers->allPreserveCaseWithoutCookies();103 $values = $response->headers->allPreserveCaseWithoutCookies();
modified tests/HttpConverterTest.php +25 -0
@@ -72,6 +72,18 @@ final class HttpConverterTest extends TestCase
7272 self::assertSame(['filter' => ['status' => 'open'], 'tags' => ['php']], $request->query->all());
7373 }
7474
75+ public function testQueryStringIgnoresTheConfiguredArgSeparator(): void
76+ {
77+ $separator = ini_set('arg_separator.output', '&');
78+ try {
79+ $request = HttpConverter::toRequest(['queryStringParameters' => ['a' => '1', 'b' => '2']]);
80+ } finally {
81+ ini_set('arg_separator.output', (string) $separator);
82+ }
83+
84+ self::assertSame(['a' => '1', 'b' => '2'], $request->query->all());
85+ }
86+
7587 public function testBase64BodyIsDecoded(): void
7688 {
7789 $binary = random_bytes(64)."\xff\xfe";
@@ -236,6 +248,19 @@ final class HttpConverterTest extends TestCase
236248 self::assertSame('chunk 1, chunk 2', HttpConverter::toFunctionResponse($response)['body']);
237249 }
238250
251+ public function testOutputBuffersLeftOpenByTheResponseAreClosed(): void
252+ {
253+ $level = ob_get_level();
254+
255+ $body = HttpConverter::toFunctionResponse(new StreamedResponse(static function (): void {
256+ ob_start();
257+ echo 'kept';
258+ }))['body'];
259+
260+ self::assertSame($level, ob_get_level());
261+ self::assertSame('kept', $body);
262+ }
263+
239264 public function testBinaryFileResponseIsBuffered(): void
240265 {
241266 $file = tempnam(sys_get_temp_dir(), 'scaleway-runtime');
@@ -72,6 +72,18 @@ final class HttpConverterTest extends TestCase
72 self::assertSame(['filter' => ['status' => 'open'], 'tags' => ['php']], $request->query->all());72 self::assertSame(['filter' => ['status' => 'open'], 'tags' => ['php']], $request->query->all());
73 }73 }
74 74
75+ public function testQueryStringIgnoresTheConfiguredArgSeparator(): void
76+ {
77+ $separator = ini_set('arg_separator.output', '&');
78+ try {
79+ $request = HttpConverter::toRequest(['queryStringParameters' => ['a' => '1', 'b' => '2']]);
80+ } finally {
81+ ini_set('arg_separator.output', (string) $separator);
82+ }
83+
84+ self::assertSame(['a' => '1', 'b' => '2'], $request->query->all());
85+ }
86+
75 public function testBase64BodyIsDecoded(): void87 public function testBase64BodyIsDecoded(): void
76 {88 {
77 $binary = random_bytes(64)."\xff\xfe";89 $binary = random_bytes(64)."\xff\xfe";
@@ -236,6 +248,19 @@ final class HttpConverterTest extends TestCase
236 self::assertSame('chunk 1, chunk 2', HttpConverter::toFunctionResponse($response)['body']);248 self::assertSame('chunk 1, chunk 2', HttpConverter::toFunctionResponse($response)['body']);
237 }249 }
238 250
251+ public function testOutputBuffersLeftOpenByTheResponseAreClosed(): void
252+ {
253+ $level = ob_get_level();
254+
255+ $body = HttpConverter::toFunctionResponse(new StreamedResponse(static function (): void {
256+ ob_start();
257+ echo 'kept';
258+ }))['body'];
259+
260+ self::assertSame($level, ob_get_level());
261+ self::assertSame('kept', $body);
262+ }
263+
239 public function testBinaryFileResponseIsBuffered(): void264 public function testBinaryFileResponseIsBuffered(): void
240 {265 {
241 $file = tempnam(sys_get_temp_dir(), 'scaleway-runtime');266 $file = tempnam(sys_get_temp_dir(), 'scaleway-runtime');