From 4ce14241e8493826b9bb8e6917ae2334c580af3f Mon Sep 17 00:00:00 2001 From: Patrick Steele-Idem Date: Fri, 26 Feb 2016 16:03:19 -0700 Subject: [PATCH] Fixes https://github.com/marko-js/async-writer/issues/3 - flush is deprecated in OutgoingMessage --- runtime/loader.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/runtime/loader.js b/runtime/loader.js index 9daca88379..57986f26b8 100644 --- a/runtime/loader.js +++ b/runtime/loader.js @@ -31,6 +31,26 @@ if (process.env.hasOwnProperty('MARKO_HOT_RELOAD')) { // enable browser-refresh require('../browser-refresh').enable(); +function fixFlush() { + try { + var OutgoingMessage = require('http').OutgoingMessage; + if (OutgoingMessage.prototype.flush && OutgoingMessage.prototype.flush.toString().indexOf('deprecated') !== -1) { + // Yes, we are monkey-patching http. This method should never have been added and it was introduced on + // the iojs fork. It was quickly deprecated and I'm 99% sure no one is actually using it. + // See: + // - https://github.com/marko-js/async-writer/issues/3 + // - https://github.com/nodejs/node/issues/2920 + // + // This method causes problems since marko looks for the flush method and calls it found. + // The `res.flush()` method is introduced by the [compression](https://www.npmjs.com/package/compression) + // middleware, but, otherwise, it should typically not exist. + delete require('http').OutgoingMessage.prototype.flush; + } + } catch(e) {} +} + +fixFlush(); + function loadSource(templatePath, compiledSrc) { var templateModulePath = templatePath + '.js';