本文整理汇总了TypeScript中builder-util-runtime.safeGetHeader函数的典型用法代码示例。如果您正苦于以下问题:TypeScript safeGetHeader函数的具体用法?TypeScript safeGetHeader怎么用?TypeScript safeGetHeader使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safeGetHeader函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: checkIsRangesSupported
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
}
示例2: safeGetHeader
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)
})
示例3: reject
const request = this.httpExecutor.doRequest(requestOptions, response => {
// 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(new HttpError(response))
}
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.on("data", dataHandler)
response.on("end", () => {
resolve()
})
})