Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ RUN \
gcc \
g++ \
git \
linux-headers \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unwanted change

openssl-dev \
curl-dev

Expand Down
9 changes: 8 additions & 1 deletion app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,13 @@ function (string $runtimeId, ?string $payload, string $path, string $method, mix

return $len;
});

$callback = function ($data) {
var_dump($data); // This will output each chunk of data as it arrives
};
\curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $data) use ($callback) {
$callback($data);
return \strlen($data);
});
\curl_setopt($ch, CURLOPT_TIMEOUT, $timeout + 5); // Gives extra 5s after safe timeout to recieve response
\curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
if ($logging == true) {
Expand All @@ -1049,6 +1055,7 @@ function (string $runtimeId, ?string $payload, string $path, string $method, mix
$headers['x-open-runtimes-logging'] = 'disabled';
}

$headers['accept'] = 'text/event-stream';
$headers['x-open-runtimes-secret'] = $secret;
$headers['x-open-runtimes-timeout'] = \max(\intval($timeout), 1);
$headersArr = [];
Expand Down
11 changes: 11 additions & 0 deletions tests/ExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,17 @@ public function provideScenarios(): array
'logging' => true,
'mimeType' => 'multipart/form-data'
],
[
'image' => 'openruntimes/node:v4-21.0',
'entrypoint' => 'index.js',
'folder' => 'node-streamed-response',
'version' => 'v4',
'startCommand' => 'cp /tmp/code.tar.gz /mnt/code/code.tar.gz && nohup helpers/start.sh "pm2 start src/server.js --no-daemon"',
'buildCommand' => 'tar -zxf /tmp/code.tar.gz -C /mnt/code && helpers/build.sh "npm i"',
'assertions' => function ($response) {
$this->assertEquals(200, $response['headers']['status-code']);
},
]
];
}

Expand Down
7 changes: 7 additions & 0 deletions tests/resources/functions/node-streamed-response/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = async (context) => {
context.res.start();
context.res.writeText('OK1');
await new Promise(resolve => setTimeout(resolve, 5000));
context.res.writeText('OK2');
return context.res.end();
};
12 changes: 12 additions & 0 deletions tests/resources/functions/node-streamed-response/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "streamed-response",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}