Skip to content

Commit db3141b

Browse files
authored
Handle DNS errors for existing hosts but wrong protocol (fixes #851) (#852)
* Handle DNS errors for existing hosts but wrong protocol (fixes #851) * Bump version * isDNSErr -> _isDNSErr
1 parent 85bd321 commit db3141b

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "testcafe-hammerhead",
33
"description": "A powerful web-proxy used as a core for the TestCafe testing framework (https://github.com/DevExpress/testcafe).",
4-
"version": "9.3.8",
4+
"version": "9.3.9",
55
"homepage": "https://github.com/DevExpress/testcafe-hammerhead",
66
"bugs": {
77
"url": "https://github.com/DevExpress/testcafe-hammerhead/issues"

src/request-pipeline/destination-request/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import { MESSAGE, getText } from '../../messages';
1212
// doesn't work (see: https://github.com/mikeal/request/issues/418).
1313
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
1414

15-
// Utils
16-
function isDNSErr (err) {
17-
return err.message && /ECONNREFUSED|ENOTFOUND/.test(err.message);
18-
}
1915

2016
// DestinationRequest
2117
export default class DestinationRequest extends EventEmitter {
@@ -24,6 +20,7 @@ export default class DestinationRequest extends EventEmitter {
2420

2521
this.req = null;
2622
this.hasResponse = false;
23+
this.aborted = false;
2724
this.opts = opts;
2825
this.isHttps = opts.protocol === 'https:';
2926
this.protocolInterface = this.isHttps ? https : http;
@@ -73,11 +70,21 @@ export default class DestinationRequest extends EventEmitter {
7370
}
7471
}
7572

73+
_abort () {
74+
this.aborted = true;
75+
this.req.abort();
76+
}
77+
78+
_isDNSErr (err) {
79+
return err.message && /ECONNREFUSED|ENOTFOUND/.test(err.message) ||
80+
!this.aborted && !this.hasResponse && err.code && /ECONNRESET/.test(err.code);
81+
}
82+
7683
_onTimeout () {
7784
// NOTE: this handler is also called if we get an error response (for example, 404). So, we should check
7885
// for the response presence before raising the timeout error.
7986
if (!this.hasResponse) {
80-
this.req.abort();
87+
this._abort();
8188
this.emit('fatalError', getText(MESSAGE.destRequestTimeout, this.opts.url));
8289
}
8390
}
@@ -88,7 +95,7 @@ export default class DestinationRequest extends EventEmitter {
8895
this._send();
8996
}
9097

91-
else if (isDNSErr(err))
98+
else if (this._isDNSErr(err))
9299
this.emit('fatalError', getText(MESSAGE.cantResolveUrl, this.opts.url));
93100
else
94101
this.emit('error');

test/server/proxy-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,24 @@ describe('Proxy', function () {
301301
request(options);
302302
});
303303

304+
it('Should pass protocol DNS errors for existing host to session', function (done) {
305+
session.handlePageError = function (ctx, err) {
306+
expect(err).eql('Failed to find a DNS-record for the resource at <a href="https://127.0.0.1:2000">https://127.0.0.1:2000</a>.');
307+
ctx.res.end();
308+
done();
309+
return true;
310+
};
311+
312+
var options = {
313+
url: proxy.openSession('https://127.0.0.1:2000', session),
314+
headers: {
315+
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*!/!*;q=0.8'
316+
}
317+
};
318+
319+
request(options);
320+
});
321+
304322
it('Should pass service message processing to session', function (done) {
305323
var options = {
306324
method: 'POST',

0 commit comments

Comments
 (0)