Skip to content

Commit

Permalink
PageProcessor parse binaries as a html page (close #521) (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
churkin authored and miherlosev committed Apr 18, 2016
1 parent 123d59d commit f9ed0b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/processing/resources/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/request-pipeline/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -168,7 +170,7 @@ export default class RequestPipelineContext {
charset.fromUrl(this.dest.charset);
}

if (this._isFileDownload())
if (isFileDownload)
this.session.handleFileDownload();

this.contentInfo = {
Expand All @@ -179,7 +181,8 @@ export default class RequestPipelineContext {
isScript,
isManifest,
encoding,
contentTypeUrlToken
contentTypeUrlToken,
isFileDownload
};
}

Expand Down
29 changes: 28 additions & 1 deletion test/server/proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<html></html>';

function trim (str) {
return str.replace(/^\s+|\s+$/g, '');
}
Expand Down Expand Up @@ -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');
});
Expand Down Expand Up @@ -205,6 +213,9 @@ describe('Proxy', function () {
return null;
};

session.handleFileDownload = function () {
};

proxy = new Proxy('127.0.0.1', 1836, 1837);
});

Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 <a href="' + host + '">' + host + '</a>.');
expect(err).eql('Failed to find a DNS-record for the resource at <a href="' + host + '">' +
host + '</a>.');
ctx.res.end();
done();
return true;
Expand Down

0 comments on commit f9ed0b8

Please sign in to comment.