新增https自定义证书功能
Signed-off-by: jinzhao <jinzhao@kaihong.com>
This commit is contained in:
parent
a7fa5de2de
commit
56c63b5637
|
@ -320,6 +320,7 @@ Clear the component content in the **aboutToRecycle** lifecycle and trigger imag
|
||||||
| onComplete | (event:EventImage \| undefined)=>void | Callback for image loading completion. Optional. |
|
| onComplete | (event:EventImage \| undefined)=>void | Callback for image loading completion. Optional. |
|
||||||
| onLoadListener | onLoadStart:()=>void,onLoadSuccess:(data:string\|Pixelmap)=>void | Callback for image loading events. Optional. |
|
| onLoadListener | onLoadStart:()=>void,onLoadSuccess:(data:string\|Pixelmap)=>void | Callback for image loading events. Optional. |
|
||||||
| downsampleOf | DownsampleStrategy | 降采样(可选) |
|
| downsampleOf | DownsampleStrategy | 降采样(可选) |
|
||||||
|
| caPath | String | Set the path of a custom certificate. Optional. |
|
||||||
### 降采样类型
|
### 降采样类型
|
||||||
| 类型 | 相关描述 |
|
| 类型 | 相关描述 |
|
||||||
|---------------------|-------------------|
|
|---------------------|-------------------|
|
||||||
|
|
|
@ -297,7 +297,7 @@ ImageKnifeAnimatorComponent({
|
||||||
| errorholderObjectFit | ImageFit | 错误图填充效果(可选) |
|
| errorholderObjectFit | ImageFit | 错误图填充效果(可选) |
|
||||||
| writeCacheStrategy | CacheStrategyType | 写入缓存策略(可选) |
|
| writeCacheStrategy | CacheStrategyType | 写入缓存策略(可选) |
|
||||||
| onlyRetrieveFromCache | boolean | 是否跳过网络和本地请求(可选) |
|
| onlyRetrieveFromCache | boolean | 是否跳过网络和本地请求(可选) |
|
||||||
| customGetImage | (context: Context, src: string | 自定义下载图片(可选) | | Resource | 错误占位图数据源 |
|
| customGetImage | (context: Context, src: string | 自定义下载图片(可选) |
|
||||||
| border | BorderOptions | 边框圆角(可选) |
|
| border | BorderOptions | 边框圆角(可选) |
|
||||||
| priority | taskpool.Priority | 加载优先级(可选) |
|
| priority | taskpool.Priority | 加载优先级(可选) |
|
||||||
| context | common.UIAbilityContext | 上下文(可选) |
|
| context | common.UIAbilityContext | 上下文(可选) |
|
||||||
|
@ -305,9 +305,10 @@ ImageKnifeAnimatorComponent({
|
||||||
| signature | String | 自定义缓存关键字(可选) |
|
| signature | String | 自定义缓存关键字(可选) |
|
||||||
| headerOption | Array<HeaderOptions> | 设置请求头(可选) |
|
| headerOption | Array<HeaderOptions> | 设置请求头(可选) |
|
||||||
| transformation | PixelMapTransformation | 图片变换(可选) |
|
| transformation | PixelMapTransformation | 图片变换(可选) |
|
||||||
| drawingColorFilter | ColorFilter | drawing.ColorFilter | 图片变换(可选) |
|
| drawingColorFilter | ColorFilter | drawing.ColorFilter |
|
||||||
| onComplete | (event:EventImage | undefined) => voi | 颜色滤镜效果(可选) |
|
| onComplete | (event:EventImage | undefined) => voi |
|
||||||
| onLoadListener | onLoadStart: () => void、onLoadSuccess: (data: string | PixelMap | undefined) => void、onLoadFailed: (err: string) => void| 监听图片加载成功与失败 |
|
| onLoadListener | onLoadStart: () => void、onLoadSuccess: (data: string | PixelMap |
|
||||||
|
| caPath | String | 设置自定义证书路径(可选) |
|
||||||
|
|
||||||
### ImageKnife接口
|
### ImageKnife接口
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -108,5 +108,6 @@ export interface RequestJobRequest {
|
||||||
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