diff --git a/frameworks/ets/ani/http/ets/@ohos.net.http.ets b/frameworks/ets/ani/http/ets/@ohos.net.http.ets index 54d6a49f8eaf58420538166feb8305ff9e6701a1..2f1d8c1b25c5b3a12ef5dbcc906904334c0e21e8 100644 --- a/frameworks/ets/ani/http/ets/@ohos.net.http.ets +++ b/frameworks/ets/ani/http/ets/@ohos.net.http.ets @@ -528,7 +528,7 @@ export default namespace http { totalSize: int; } - native function createHttpResponseCache(cacheSize?: int): HttpResponseCache; + export native function createHttpResponseCache(cacheSize?: int): HttpResponseCache; export interface HttpResponseCache { flush(callback: AsyncCallback): void; diff --git a/frameworks/ets/ani/http/src/bridge.rs b/frameworks/ets/ani/http/src/bridge.rs index ea65dfe119fb69ec15c1d6eff78cd93305d411c7..0a9baefed5c986cd38156d31d80ff95389cddd45 100644 --- a/frameworks/ets/ani/http/src/bridge.rs +++ b/frameworks/ets/ani/http/src/bridge.rs @@ -382,7 +382,7 @@ pub struct DataSendProgressInfo { pub total_size: i32, } -#[ani_rs::ani] +#[ani_rs::ani(path = "L@ohos/net/http/http/HttpResponseCacheInner")] pub struct HttpResponseCache { pub native_ptr: i64, } diff --git a/frameworks/ets/ani/http/src/http.rs b/frameworks/ets/ani/http/src/http.rs index 17b050f285f4ac188f5fd65eb57b82e3c25e16f5..9974d85ac46361c60ef87a55c6cbd0139b0ae52d 100644 --- a/frameworks/ets/ani/http/src/http.rs +++ b/frameworks/ets/ani/http/src/http.rs @@ -85,6 +85,20 @@ pub fn http_set_options(request: &mut Request, options: HttpReques } } +#[ani_rs::native] +pub fn create_http_response_cache<'local>( + env: &AniEnv<'local>, cacheSize : Option) -> Result, BusinessError> { + static HTTP_RESPONSE_CACHE_CLASS: &CStr = + unsafe { CStr::from_bytes_with_nul_unchecked(b"L@ohos/net/http/http/HttpResponseCacheInner;\0") }; + static CTOR_SIGNATURE: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"J:V\0") }; + + let class = env.find_class(HTTP_RESPONSE_CACHE_CLASS).unwrap(); + let obj = env + .new_object_with_signature(&class, CTOR_SIGNATURE, (0,)) + .unwrap(); + Ok(obj.into()) +} + #[ani_rs::native] pub(crate) fn request( env: &AniEnv, diff --git a/frameworks/ets/ani/http/src/lib.rs b/frameworks/ets/ani/http/src/lib.rs index d8fdbd3bbd34d46df7314f5d6e12e1045f857b61..e0be6b34a9e1794b35cc622cd478ce233b88122f 100644 --- a/frameworks/ets/ani/http/src/lib.rs +++ b/frameworks/ets/ani/http/src/lib.rs @@ -27,7 +27,8 @@ mod http; ani_rs::ani_constructor! { namespace "L@ohos/net/http/http" [ - "createHttp" : http::create_http + "createHttp" : http::create_http, + "createHttpResponseCache" : http::create_http_response_cache ] class "L@ohos/net/http/http/HttpRequestInner" [