From 718a9e403248da1e2770567c63eaeccb5b19c4b6 Mon Sep 17 00:00:00 2001 From: leo9001 Date: Mon, 1 Sep 2025 17:21:40 +0800 Subject: [PATCH] =?UTF-8?q?http=20=E6=94=AF=E6=8C=81=20create=5Fhttp=5Fres?= =?UTF-8?q?ponse=5Fcache=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: leo9001 --- frameworks/ets/ani/http/ets/@ohos.net.http.ets | 2 +- frameworks/ets/ani/http/src/bridge.rs | 2 +- frameworks/ets/ani/http/src/http.rs | 14 ++++++++++++++ frameworks/ets/ani/http/src/lib.rs | 3 ++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/frameworks/ets/ani/http/ets/@ohos.net.http.ets b/frameworks/ets/ani/http/ets/@ohos.net.http.ets index 54d6a49f8..2f1d8c1b2 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 ea65dfe11..0a9baefed 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 17b050f28..9974d85ac 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 d8fdbd3bb..e0be6b34a 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" [ -- Gitee