Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function checkIsRangesSupported(response: IncomingMessage, reject: (error: Error) => void): boolean {
// Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.
if (response.statusCode!! >= 400) {
reject(createHttpError(response))
return false
}
if (response.statusCode !== 206) {
const acceptRanges = safeGetHeader(response, "accept-ranges")
if (acceptRanges == null || acceptRanges === "none") {
reject(new Error(`Server doesn't support Accept-Ranges (response code ${response.statusCode})`))
return false
}
}
return true
}
const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {
if (!checkIsRangesSupported(response, reject)) {
return
}
const contentType = safeGetHeader(response, "content-type")
const m = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i.exec(contentType)
if (m == null) {
reject(new Error(`Content-Type "multipart/byteranges" is expected, but got "${contentType}"`))
return
}
const dicer = new DataSplitter(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, resolve)
dicer.on("error", reject)
response.pipe(dicer)
})
differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)