新增https自定义证书功能
This commit is contained in:
parent
a7fa5de2de
commit
e4dba79dc2
|
@ -76,7 +76,9 @@ struct SingleImage {
|
||||||
placeholderSrc: $r("app.media.loading"),
|
placeholderSrc: $r("app.media.loading"),
|
||||||
errorholderSrc: $r("app.media.failed"),
|
errorholderSrc: $r("app.media.failed"),
|
||||||
objectFit: ImageFit.Contain,
|
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)
|
}).width(100).height(100)
|
||||||
Text($r('app.string.Custom_network_download'))
|
Text($r('app.string.Custom_network_download'))
|
||||||
|
|
|
@ -188,6 +188,7 @@ export class ImageKnifeDispatcher {
|
||||||
targetWidth: currentRequest.componentWidth,
|
targetWidth: currentRequest.componentWidth,
|
||||||
targetHeight: currentRequest.componentHeight,
|
targetHeight: currentRequest.componentHeight,
|
||||||
downsampType: currentRequest.imageKnifeOption.downsampleOf==undefined?DownsampleStrategy.NONE:currentRequest.imageKnifeOption.downsampleOf,
|
downsampType: currentRequest.imageKnifeOption.downsampleOf==undefined?DownsampleStrategy.NONE:currentRequest.imageKnifeOption.downsampleOf,
|
||||||
|
caPath: currentRequest.imageKnifeOption.caPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
if(request.customGetImage == undefined) {
|
if(request.customGetImage == undefined) {
|
||||||
|
|
|
@ -289,6 +289,8 @@ 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,
|
||||||
|
@ -298,7 +300,6 @@ export class ImageKnifeLoader {
|
||||||
// usingProtocol:http.HttpProtocol.HTTP1_1
|
// usingProtocol:http.HttpProtocol.HTTP1_1
|
||||||
// header: new Header('application/json')
|
// header: new Header('application/json')
|
||||||
});
|
});
|
||||||
|
|
||||||
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)
|
||||||
|
@ -309,6 +310,29 @@ export class ImageKnifeLoader {
|
||||||
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) {
|
||||||
LogUtil.log("ImageKnife_DataTime_requestJob_saveFileCacheOnlyFile.start:"+request.src)
|
LogUtil.log("ImageKnife_DataTime_requestJob_saveFileCacheOnlyFile.start:"+request.src)
|
||||||
|
|
|
@ -107,6 +107,7 @@ export interface RequestJobRequest {
|
||||||
resName?: string,
|
resName?: string,
|
||||||
targetWidth: number
|
targetWidth: number
|
||||||
targetHeight: number
|
targetHeight: number
|
||||||
downsampType: DownsampleStrategy
|
downsampType: DownsampleStrategy,
|
||||||
|
caPath?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,8 @@ interface ImageOption {
|
||||||
onComplete?:(event:EventImage | undefined) => void
|
onComplete?:(event:EventImage | undefined) => void
|
||||||
drawingColorFilter?: ColorFilter | drawing.ColorFilter
|
drawingColorFilter?: ColorFilter | drawing.ColorFilter
|
||||||
downsampleOf?: DownsampleStrategy
|
downsampleOf?: DownsampleStrategy
|
||||||
|
// 自定义证书路径
|
||||||
|
caPath?: string
|
||||||
}
|
}
|
||||||
@ObservedV2
|
@ObservedV2
|
||||||
export class ImageKnifeOption {
|
export class ImageKnifeOption {
|
||||||
|
@ -125,6 +127,8 @@ export class ImageKnifeOption {
|
||||||
drawingColorFilter?: ColorFilter | drawing.ColorFilter
|
drawingColorFilter?: ColorFilter | drawing.ColorFilter
|
||||||
// 下采样
|
// 下采样
|
||||||
@Trace downsampleOf: DownsampleStrategy = DownsampleStrategy.NONE
|
@Trace downsampleOf: DownsampleStrategy = DownsampleStrategy.NONE
|
||||||
|
// 自定义证书路径
|
||||||
|
caPath?: string
|
||||||
constructor(option?:ImageOption) {
|
constructor(option?:ImageOption) {
|
||||||
this.loadSrc = option?.loadSrc == undefined ? "" : option?.loadSrc
|
this.loadSrc = option?.loadSrc == undefined ? "" : option?.loadSrc
|
||||||
this.placeholderSrc = option?.placeholderSrc
|
this.placeholderSrc = option?.placeholderSrc
|
||||||
|
@ -146,6 +150,7 @@ export class ImageKnifeOption {
|
||||||
this.onComplete = option?.onComplete
|
this.onComplete = option?.onComplete
|
||||||
this.drawingColorFilter = option?.drawingColorFilter
|
this.drawingColorFilter = option?.drawingColorFilter
|
||||||
this.downsampleOf = option?.downsampleOf==undefined?DownsampleStrategy.NONE:option?.downsampleOf
|
this.downsampleOf = option?.downsampleOf==undefined?DownsampleStrategy.NONE:option?.downsampleOf
|
||||||
|
this.caPath = option?.caPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue