Skip to content

Commit

Permalink
Retry with GET request in some situations when HEAD request fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Munter committed May 13, 2017
1 parent a9f96f7 commit bbe9aa0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ module.exports = function (options) {
}
}

function httpStatus(url, relations, shouldUseGetMethod) {
function httpStatus(url, relations, retryWithGetMethod) {
return function (callback) {
request({
method: shouldUseGetMethod ? 'get' : 'head',
method: retryWithGetMethod ? 'get' : 'head',
url: url.replace(/#.*$/, ''),
strictSSL: true,
gzip: true,
Expand All @@ -169,6 +169,11 @@ module.exports = function (options) {
var code = error.code;

if (code) {
// Some servers send responses that request apparently handles badly when using the HEAD method...
if (code === 'HPE_INVALID_CONSTANT' && !retryWithGetMethod) {
return httpStatus(url, relations, true)(callback);
}

if (code === 'ENOTFOUND') {
status = 'DNS Missing';
} else {
Expand All @@ -182,7 +187,7 @@ module.exports = function (options) {

callback(undefined, status);
} else {
if (res.statusCode === 405) {
if (!retryWithGetMethod && res.statusCode >= 400 && res.statusCode < 500) {
return httpStatus(url, relations, true)(callback);
}

Expand Down

0 comments on commit bbe9aa0

Please sign in to comment.