Skip to content

Commit

Permalink
fixed #52, ENOTFOUND, Domain name not found when request was not inte…
Browse files Browse the repository at this point in the history
…rcepted and port was not standard
  • Loading branch information
pgte committed Mar 28, 2012
1 parent cc25f10 commit 0b3c034
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
15 changes: 12 additions & 3 deletions lib/intercept.js
Expand Up @@ -48,16 +48,25 @@ function interceptorsFor(options) {
options.host = options.hostname;
}

// if (
// options.port && options.host.indexOf(':') < 0 &&
// (options.port !== 80 || options.proto !== 'http') &&
// (options.port !== 443 || options.proto !== 'https')
// ) {
// options.host += ":" + options.port;
// delete options.port;
// }

basePath = options.proto + '://' + options.host;
if (
options.port && options.host.indexOf(':') < 0 &&
(options.port !== 80 || options.proto !== 'http') &&
(options.port !== 443 || options.proto !== 'https')
) {
options.host += ":" + options.port;
delete options.port;
basePath += ":" + options.port;
}

basePath = options.proto + '://' + options.host;
console.log('basePath:', basePath)

return allInterceptors[basePath] || [];
}
Expand Down
11 changes: 10 additions & 1 deletion lib/scope.js
Expand Up @@ -113,12 +113,21 @@ function startScope(basePath, options) {
var checkHeaders = function(header) {
return options.getHeader(header.name) === header.value;
};

if (!matchHeaders.every(checkHeaders) ||
!interceptorMatchHeaders.every(checkHeaders)) {
return false;
}

var matchKey = method + ' ' + proto + '://' + options.host + path;
var matchKey = method + ' ' + proto + '://' + options.host;
if (
options.port && options.host.indexOf(':') < 0 &&
(options.port !== 80 || options.proto !== 'http') &&
(options.port !== 443 || options.proto !== 'https')
) {
matchKey += ":" + options.port;
}
matchKey += path;
if (body) { matchKey += (' ' + body); }
matches = matchKey === this._key;
logger('matching ' + matchKey + ' to ' + this._key + ': ' + matches);
Expand Down

0 comments on commit 0b3c034

Please sign in to comment.