[英]Enabling Google Cloud Run chunked encoding
I have tried returning 'transfer-encoding:chunked' header to a large download but the response terminated at "31.9M" which is very close to the documented "32MB" limit.我尝试将“transfer-encoding:chunked”header 返回到大型下载,但响应终止于“31.9M”,这非常接近记录的“32MB”限制。
The Unofficial FAQ states chunked encoding is now possible, but I can't seem to get it working. 非官方常见问题解答指出分块编码现在是可能的,但我似乎无法让它工作。
Do I have to flip any flags (eg https/2) to enable streaming?我是否必须翻转任何标志(例如 https/2)才能启用流式传输? Is it only possible in some regions?
是不是只有部分地区可以? (I am using europe-west1)
(我正在使用 europe-west1)
The following minimal case does actually stream 45MB over Cloud Run, without any special configuration, confirmed in us-central1 and europe-west1以下最小案例实际上 stream 45MB over Cloud Run,无需任何特殊配置,在 us-central1 和 europe-west1 中确认
FROM node:14-slim
COPY index.js index.js
CMD [ "node", "index.js" ]
const http = require('http');
http.createServer((request, response) => {
response.setHeader('Transfer-Encoding', 'chunked');
// 45MB
var i = 1000000;
function nextChunk() {
return new Promise(resolve => {
if (i-- > 0) {
response.write(
'123456781234567812345678123456781234567812345678',
() => nextChunk()
);
} else {
response.end();
}
})
};
Promise.all(nextChunk())
}).listen(process.env.PORT || 8080);
Even after straming into chunks I'm always getting error after 32 MB reponse size, I can't get the response header 'Transfer-Encoding' = 'chunked' from Cloud Run service response:即使在进入块后我总是在 32 MB 响应大小后出现错误,我无法从 Cloud Run 服务响应中获得响应 header 'Transfer-Encoding' = 'chunked':
I'm using NestJs, and I can get it in the response Headers when I execute the app locally.我正在使用 NestJs,当我在本地执行应用程序时,我可以在响应标头中获取它。
I'm specifying it as:我将其指定为:
@Get('streamable')
@Header('Transfer-Encoding', 'chunked')
async streamable(@Res() res) { etc.. res.write(chunk)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.