我一直在运行Node 0.8.25和Express 3.4.0。
效果很好。
我尝试升级到Node 0.10 Stable,我开始遇到奇怪的问题。
例如,我有一条看起来像这样的路线:
app.post( "/toPDF", auth.isAuthorized, function( req, res, next ){
getPDF( req.data, function( err, pdfData ) {
if ( err ) {
next( err );
} else {
res.setHeader( "Content-type", "application/pdf" );
res.setHeader( "Cache-Control", "no-cache" );
res.setHeader( "Accept-Ranges", "none" );
res.setHeader( "Content-Disposition", "inline; filename=stuff.pdf" );
res.end( pdfData.raw, "binary" );
}
});
});
升级到Node 0.10后,第一次调用此路由时,一切都按预期工作。
然而,第二次调用路由时,应用程序崩溃并显示错误“Headers already sent。”
我想查看响应中已存在哪些标头。因此,在发送任何标头之前,我将以下内容添加到getPDF回调的顶部。
console.log( res._headers );
在它崩溃之前,输出:
Content-type application/pdf
Cache-Control no-cache
Accept-Ranges none
Content-Disposition inline; filname = stuff.pdf
看起来我的旧响应对象是以某种方式悬挂?任何想法可能会在这里发生什么?