diff --git a/src/processing/resources/page.js b/src/processing/resources/page.js
index cfcabffdc..770e05d71 100644
--- a/src/processing/resources/page.js
+++ b/src/processing/resources/page.js
@@ -126,7 +126,8 @@ class PageProcessor extends ResourceProcessorBase {
shouldProcessResource (ctx) {
// NOTE: In some cases, Firefox sends the default accept header for the script.
// We should not try to process it as a page in this case.
- return (ctx.isPage || ctx.contentInfo.isIframeWithImageSrc) && !ctx.contentInfo.isScript;
+ return (ctx.isPage || ctx.contentInfo.isIframeWithImageSrc) && !ctx.contentInfo.isScript &&
+ !ctx.contentInfo.isFileDownload;
}
processResource (html, ctx, charset, urlReplacer, processingOpts) {
diff --git a/src/request-pipeline/context.js b/src/request-pipeline/context.js
index 601cbaf89..c98c3c94c 100644
--- a/src/request-pipeline/context.js
+++ b/src/request-pipeline/context.js
@@ -155,6 +155,8 @@ export default class RequestPipelineContext {
var requireProcessing = !this.isXhr && !isFormWithEmptyResponse && !isRedirect &&
(this.isPage || this.isIframe || requireAssetsProcessing);
+ var isFileDownload = this._isFileDownload();
+
var isIframeWithImageSrc = this.isIframe && !this.isPage && /^\s*image\//.test(contentType);
var charset = null;
@@ -168,7 +170,7 @@ export default class RequestPipelineContext {
charset.fromUrl(this.dest.charset);
}
- if (this._isFileDownload())
+ if (isFileDownload)
this.session.handleFileDownload();
this.contentInfo = {
@@ -179,7 +181,8 @@ export default class RequestPipelineContext {
isScript,
isManifest,
encoding,
- contentTypeUrlToken
+ contentTypeUrlToken,
+ isFileDownload
};
}
diff --git a/test/server/proxy-test.js b/test/server/proxy-test.js
index a6bcce2b2..ecb57f5b7 100644
--- a/test/server/proxy-test.js
+++ b/test/server/proxy-test.js
@@ -17,6 +17,8 @@ var requestAgent = require('../../lib/request-pipeline/destinatio
var scriptHeader = require('../../lib/processing/script/header').HEADER;
var urlUtils = require('../../lib/utils/url');
+var EMPTY_PAGE = '';
+
function trim (str) {
return str.replace(/^\s+|\s+$/g, '');
}
@@ -105,6 +107,12 @@ describe('Proxy', function () {
res.end('42');
});
+ app.get('/download', function (req, res) {
+ res.set('content-disposition', 'attachment;filename=DevExpressTestCafe-15.1.2.exe');
+ res.end(EMPTY_PAGE);
+
+ });
+
app.options('/preflight', function (req, res) {
res.end('42');
});
@@ -205,6 +213,9 @@ describe('Proxy', function () {
return null;
};
+ session.handleFileDownload = function () {
+ };
+
proxy = new Proxy('127.0.0.1', 1836, 1837);
});
@@ -549,6 +560,21 @@ describe('Proxy', function () {
done();
});
});
+
+ it('Should not process file download', function (done) {
+ var options = {
+ url: proxy.openSession('http://127.0.0.1:2000/download', session),
+ method: 'GET',
+ headers: {
+ accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*!/!*;q=0.8'
+ }
+ };
+
+ request(options, function (err, res, body) {
+ expect(body).eql(EMPTY_PAGE);
+ done();
+ });
+ });
});
describe('Basic authentication', function () {
@@ -840,7 +866,8 @@ describe('Proxy', function () {
var host = 'http://127.0.0.1:' + port;
session.handlePageError = function (ctx, err) {
- expect(err).eql('Failed to find a DNS-record for the resource at ' + host + '.');
+ expect(err).eql('Failed to find a DNS-record for the resource at ' +
+ host + '.');
ctx.res.end();
done();
return true;