优化caPath相关代码

Signed-off-by: jinzhao <jinzhao@kaihong.com>
This commit is contained in:
jinzhao 2024-10-30 10:52:19 +08:00
parent 56c63b5637
commit accb47febd
1 changed files with 20 additions and 42 deletions

View File

@ -290,48 +290,26 @@ export class ImageKnifeLoader {
}) })
} }
if(request.caPath === undefined) { //采用默认证书 let promise = httpRequest.requestInStream(request.src, {
let promise = httpRequest.requestInStream(request.src, { header: headerObj,
header: headerObj, method: http.RequestMethod.GET,
method: http.RequestMethod.GET, expectDataType: http.HttpDataType.ARRAY_BUFFER,
expectDataType: http.HttpDataType.ARRAY_BUFFER, connectTimeout: 60000,
connectTimeout: 60000, readTimeout: 0,
readTimeout: 0, // usingProtocol:http.HttpProtocol.HTTP1_1
// usingProtocol:http.HttpProtocol.HTTP1_1 // header: new Header('application/json')
// header: new Header('application/json') caPath: request.caPath === undefined ? undefined : request.caPath,
}); });
await promise.then((data: number) => { await promise.then((data: number) => {
if (data == 200 || data == 206 || data == 204) { if (data == 200 || data == 206 || data == 204) {
resBuf = combineArrayBuffers(arrayBuffers) resBuf = combineArrayBuffers(arrayBuffers)
} else { } else {
throw new Error("HttpDownloadClient has error, http code =" + JSON.stringify(data)) throw new Error("HttpDownloadClient has error, http code =" + JSON.stringify(data))
} }
}).catch((err: Error) => { }).catch((err: Error) => {
throw new Error("HttpDownloadClient download ERROR : err = " + JSON.stringify(err)) throw new Error("HttpDownloadClient download ERROR : err = " + JSON.stringify(err))
}); });
LogUtil.log("HttpDownloadClient.end:" + request.src) LogUtil.log("HttpDownloadClient.end:" + request.src)
} else { //采用自定义证书
let promise = httpRequest.requestInStream(request.src, {
header: headerObj,
method: http.RequestMethod.GET,
expectDataType: http.HttpDataType.ARRAY_BUFFER,
connectTimeout: 60000,
readTimeout: 0,
// usingProtocol:http.HttpProtocol.HTTP1_1
// header: new Header('application/json')
caPath: request.caPath,
});
await promise.then((data: number) => {
if (data == 200 || data == 206 || data == 204) {
resBuf = combineArrayBuffers(arrayBuffers)
} else {
throw new Error("HttpDownloadClient has error, http code =" + JSON.stringify(data))
}
}).catch((err: Error) => {
throw new Error("HttpDownloadClient download ERROR : err = " + JSON.stringify(err))
});
LogUtil.log("HttpDownloadClient.end:" + request.src)
}
// 保存文件缓存 // 保存文件缓存
if (resBuf !== undefined && request.writeCacheStrategy !== CacheStrategy.Memory) { if (resBuf !== undefined && request.writeCacheStrategy !== CacheStrategy.Memory) {