function (res, mediaTypes) {
    var contentTypeOk,
        result = "status: '" + res.statusCode + "', GET failed.";

    mediaTypes = !Array.isArray(mediaTypes) ? [mediaTypes] : mediaTypes;

    if (res.statusCode === 200) {
      // if content-type exists, and media type found then contentTypeOk
      contentTypeOk =
        res.headers["content-type"] &&
        // empty array and none found return true
        !mediaTypes.every(function(mediaType) {
          // flip -1 to 0 and NOT, so that true == NOT found, found stops loop w/false
          return !~res.headers["content-type"].indexOf(mediaType);
        });

      result = contentTypeOk ? "" : "content-type not one of '"+mediaTypes.join(",")+"'";
    }

    return result;
  }
function (res, mediaTypes) {
    var contentTypeOk,
        result = "status: '" + res.statusCode + "', GET failed.";

    mediaTypes = !Array.isArray(mediaTypes) ? [mediaTypes] : mediaTypes;

    if (res.statusCode === 200) {
      // if content-type exists, and media type found then contentTypeOk
      contentTypeOk =
        res.headers["content-type"] &&
        // empty array and none found return true
        !mediaTypes.every(function(mediaType) {
          // flip -1 to 0 and NOT, so that true == NOT found, found stops loop w/false
          return !~res.headers["content-type"].indexOf(mediaType);
        });

      result = contentTypeOk ? "" : "content-type not one of '"+mediaTypes.join(",")+"'";
    }

    return result;
  }
function ( res , mediaTypes ) { var contentTypeOk , result = "status: '" + res . statusCode + "', GET failed." ; mediaTypes = ! Array . isArray ( mediaTypes ) ? [ mediaTypes ] : mediaTypes ; if ( res . statusCode === 200 ) { // if content-type exists, and media type found then contentTypeOk contentTypeOk = res . headers [ "content-type" ] && // empty array and none found return true ! mediaTypes . every ( function ( mediaType ) { // flip -1 to 0 and NOT, so that true == NOT found, found stops loop w/false return ! ~ res . headers [ "content-type" ] . indexOf ( mediaType ) ; } ) ; result = contentTypeOk ? "" : "content-type not one of '" + mediaTypes . join ( "," ) + "'" ; } return result ; }
Simple response checker for remote files.
Expected use in robots.txt or sitemap.xml only.

@param {IncomingMessage} res - The IncomingMessage response to check.
@param {Array} mediaTypes - array of acceptable content-type media type strings.
@returns {String} Error message, empty string (falsy) if OK.
Simple response checker for remote files . Expected use in robots . txt or sitemap . xml only .