Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (err) {
// Browsers allow HTTP redirects for simple cross-origin
// requests but not for requests that require preflight.
// Use a simple request to unravel any redirects and get the
// final URL. Retry the original request with the new URL if
// it's different.
//
// This test is imperfect but it's simple and good for common
// cases. It catches all cross-origin cases but matches a few
// same-origin cases too.
if (typeof window === 'undefined' || url.startsWith(`${window.location.origin}/`)) {
hasError = true
return cb(err)
}
return get.head(url, (errHead, res) => {
if (hasError) return
if (errHead) {
hasError = true
return cb(errHead)
}
if (res.statusCode < 200 || res.statusCode >= 300) {
hasError = true
return cb(new Error(`Unexpected HTTP status code ${res.statusCode}`))
}
if (res.url === url) {
hasError = true
return cb(err)
}
opts.url = res.url
get.concat(opts, (err, res, data) => {
if (err) {
// Browsers allow HTTP redirects for simple cross-origin
// requests but not for requests that require preflight.
// Use a simple request to unravel any redirects and get the
// final URL. Retry the original request with the new URL if
// it's different.
//
// This test is imperfect but it's simple and good for common
// cases. It catches all cross-origin cases but matches a few
// same-origin cases too.
if (typeof window === 'undefined' || url.startsWith(window.location.origin + '/')) {
hasError = true
return cb(err)
}
return get.head(url, function (errHead, res) {
if (hasError) return
if (errHead) {
hasError = true
return cb(errHead)
}
if (res.statusCode < 200 || res.statusCode >= 300) {
hasError = true
return cb(new Error('Unexpected HTTP status code ' + res.statusCode))
}
if (res.url === url) {
hasError = true
return cb(err)
}
opts.url = res.url
get.concat(opts, function (err, res, data) {
return function (cb) {
get.head(REGISTRY_URL + name, function (err, res) {
if (err) return cb(err)
if (res.statusCode === 404) next(null, name)
res.resume() // consume the stream
cb(null)
})
}
})
return function (cb) {
console.log('checking ' + pkg.repo + '...')
get.head(pkg.repo, function (err, res) {
if (res.statusCode !== 200) {
err = new Error('Non-200 status code ' + res.statusCode)
}
if (err) {
err.message = pkg.name + ': ' + err.message
cb(err)
} else {
cb(null)
}
})
}
}), function (err) {