新增https自定义证书功能
This commit is contained in:
parent
a7fa5de2de
commit
e4dba79dc2
|
@ -76,7 +76,9 @@ struct SingleImage {
|
|||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
objectFit: ImageFit.Contain,
|
||||
progressListener:(progress:number)=>{console.info("ImageKnife:: call back progress = " + progress)}
|
||||
progressListener:(progress:number)=>{console.info("ImageKnife:: call back progress = " + progress)},
|
||||
// 通过https协议进行连接时,默认使用系统预设CA证书。若希望使用自定义证书进行https连接,则需要将自定义证书上传至应用沙箱目录中,并在caPath中指定该证书所在的应用沙箱路径
|
||||
// caPath: "/data/storage/el1/bundle/ca.pem",
|
||||
})
|
||||
}).width(100).height(100)
|
||||
Text($r('app.string.Custom_network_download'))
|
||||
|
|
|
@ -188,6 +188,7 @@ export class ImageKnifeDispatcher {
|
|||
targetWidth: currentRequest.componentWidth,
|
||||
targetHeight: currentRequest.componentHeight,
|
||||
downsampType: currentRequest.imageKnifeOption.downsampleOf==undefined?DownsampleStrategy.NONE:currentRequest.imageKnifeOption.downsampleOf,
|
||||
caPath: currentRequest.imageKnifeOption.caPath,
|
||||
}
|
||||
|
||||
if(request.customGetImage == undefined) {
|
||||
|
|
|
@ -289,6 +289,8 @@ export class ImageKnifeLoader {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
if(request.caPath === undefined) { //采用默认证书
|
||||
let promise = httpRequest.requestInStream(request.src, {
|
||||
header: headerObj,
|
||||
method: http.RequestMethod.GET,
|
||||
|
@ -298,7 +300,6 @@ export class ImageKnifeLoader {
|
|||
// usingProtocol:http.HttpProtocol.HTTP1_1
|
||||
// header: new Header('application/json')
|
||||
});
|
||||
|
||||
await promise.then((data: number) => {
|
||||
if (data == 200 || data == 206 || data == 204) {
|
||||
resBuf = combineArrayBuffers(arrayBuffers)
|
||||
|
@ -309,6 +310,29 @@ export class ImageKnifeLoader {
|
|||
throw new Error("HttpDownloadClient download ERROR : err = " + JSON.stringify(err))
|
||||
});
|
||||
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) {
|
||||
LogUtil.log("ImageKnife_DataTime_requestJob_saveFileCacheOnlyFile.start:"+request.src)
|
||||
|
|
|
@ -107,6 +107,7 @@ export interface RequestJobRequest {
|
|||
resName?: string,
|
||||
targetWidth: number
|
||||
targetHeight: number
|
||||
downsampType: DownsampleStrategy
|
||||
downsampType: DownsampleStrategy,
|
||||
caPath?: string,
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,8 @@ interface ImageOption {
|
|||
onComplete?:(event:EventImage | undefined) => void
|
||||
drawingColorFilter?: ColorFilter | drawing.ColorFilter
|
||||
downsampleOf?: DownsampleStrategy
|
||||
// 自定义证书路径
|
||||
caPath?: string
|
||||
}
|
||||
@ObservedV2
|
||||
export class ImageKnifeOption {
|
||||
|
@ -125,6 +127,8 @@ export class ImageKnifeOption {
|
|||
drawingColorFilter?: ColorFilter | drawing.ColorFilter
|
||||
// 下采样
|
||||
@Trace downsampleOf: DownsampleStrategy = DownsampleStrategy.NONE
|
||||
// 自定义证书路径
|
||||
caPath?: string
|
||||
constructor(option?:ImageOption) {
|
||||
this.loadSrc = option?.loadSrc == undefined ? "" : option?.loadSrc
|
||||
this.placeholderSrc = option?.placeholderSrc
|
||||
|
@ -146,6 +150,7 @@ export class ImageKnifeOption {
|
|||
this.onComplete = option?.onComplete
|
||||
this.drawingColorFilter = option?.drawingColorFilter
|
||||
this.downsampleOf = option?.downsampleOf==undefined?DownsampleStrategy.NONE:option?.downsampleOf
|
||||
this.caPath = option?.caPath
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue