Node.js:响应的管道流通过HTTPS冻结

编程入门 行业动态 更新时间:2024-10-13 10:29:00
本文介绍了Node.js:响应的管道流通过HTTPS冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 Connect 来提供静态内容,但是使用大文件(> 40KB) ),发送第一个40,960字节的块(有时是32,940字节),然后传输休眠2分钟,然后传输完成。我发现当我将流传输到响应时会发生这种情况(这就是Connect发送响应的方式)。

I'm trying to use Connect to serve static content, but with large files (> 40KB), a first chunk of 40,960 bytes is sent (sometimes 32,940 bytes), then the transfer sleeps for 2 minutes, then the transfer finishes. I found out that it happens when I pipe a stream to the response (this is how Connect sends the response).

这是在节点0.6上重现这一点的代码.2,在Windows和Linux上,文件为48,980字节:

Here is a code the reproduces this, on Node 0.6.2, on Windows and Linux, with a 48,980 bytes file:

var fs = require( "fs" ), https = require("https"); var privateKey = fs.readFileSync( 'privatekey.pem' ).toString(); var certificate = fs.readFileSync( 'certificate.pem' ).toString(); var options = {key: privateKey, cert: certificate}; var server = https.createServer( options, function( req, res ) { var path = __dirname + "/public" + req.url; fs.stat(path, function(err, stat){ if( err ) { res.writeHead(404, {'Content-Type': 'text/html'}); res.end(""+err); } else { res.writeHead(200, { 'Content-Type': 'text/html', 'Content-Length': stat.size}); var stream = fs.createReadStream(path); stream.pipe(res); } } ); } ).listen(8364);

使用 fs.readFile ,我无法重现:

var fs = require( "fs" ), https = require("https"); var privateKey = fs.readFileSync( 'privatekey.pem' ).toString(); var certificate = fs.readFileSync( 'certificate.pem' ).toString(); var options = {key: privateKey, cert: certificate}; var server = https.createServer( options, function( req, res ) { fs.readFile(__dirname + "/public" + req.url, function(err, data){ if( err ) { res.writeHead(404, {'Content-Type': 'text/html'}); res.end(""+err); } else { res.writeHead(200, { 'Content-Type': 'text/html', 'Content-Length': data.length}); res.end(data); } } ); } ).listen(8364);

我做错了什么?

推荐答案

就是这个问题: github/ joyent / node / issues / 2198

已在Node 0.6.4中修复!

Fixed in Node 0.6.4!

更多推荐

Node.js:响应的管道流通过HTTPS冻结

本文发布于:2023-11-24 02:17:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623608.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管道   Node   js   HTTPS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!