From 99baa8914ff2a57db14d20bc9ab5bebf6f6a0040 Mon Sep 17 00:00:00 2001 From: jxw Date: Fri, 18 Jul 2025 16:58:02 +0800 Subject: [PATCH] fix http Signed-off-by: jxw --- bundle.json | 4 +- .../js/napi/http/http_exec/src/http_exec.cpp | 4 +- utils/napi_utils/BUILD.gn | 4 ++ utils/napi_utils/include/napi_utils.h | 4 ++ utils/napi_utils/src/napi_utils.cpp | 46 +++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/bundle.json b/bundle.json index b1da5cfc8..38c6b7a50 100644 --- a/bundle.json +++ b/bundle.json @@ -58,7 +58,9 @@ "node", "jsoncpp", "access_token", - "hiappevent" + "hiappevent", + "bundle_framework", + "safwk" ] }, "build": { diff --git a/frameworks/js/napi/http/http_exec/src/http_exec.cpp b/frameworks/js/napi/http/http_exec/src/http_exec.cpp index 553edc02f..c15f0f6e4 100755 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -280,7 +280,9 @@ bool HttpExec::AddCurlHandle(CURL *handle, RequestContext *context) #if HAS_NETMANAGER_BASE std::stringstream name; - name << HTTP_REQ_TRACE_NAME << "_" << std::this_thread::get_id(); + auto isDebugMode = NapiUtils::IsDebugMode(); + auto urlWithoutParam = NapiUtils::removeUrlParameters(context->options.GetUrl()); + name << HTTP_REQ_TRACE_NAME << "_" << std::this_thread::get_id() << (isDebugMode ? ("_" + urlWithoutParam) : ""); SetTraceOptions(handle, context); SetServerSSLCertOption(handle, context); diff --git a/utils/napi_utils/BUILD.gn b/utils/napi_utils/BUILD.gn index 604c83618..970e517e1 100644 --- a/utils/napi_utils/BUILD.gn +++ b/utils/napi_utils/BUILD.gn @@ -54,6 +54,10 @@ ohos_static_library("napi_utils") { "c_utils:utils", "hilog:libhilog", "napi:ace_napi", + "samgr:samgr_proxy", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "safwk:system_ability_fwk", ] if (!build_ohos_sdk) { diff --git a/utils/napi_utils/include/napi_utils.h b/utils/napi_utils/include/napi_utils.h index ea99529ae..1d522870b 100644 --- a/utils/napi_utils/include/napi_utils.h +++ b/utils/napi_utils/include/napi_utils.h @@ -182,6 +182,10 @@ uint64_t CreateUvHandlerQueue(napi_env env); void HookForEnvCleanup(void *data); void SetEnvValid(napi_env env); bool IsEnvValid(napi_env env); + +bool IsDebugMode(); + +std::string removeUrlParameters(const std::string& url); } // namespace OHOS::NetStack::NapiUtils #endif /* COMMUNICATIONNETSTACK_NETSTACK_NAPI_UTILS_H */ diff --git a/utils/napi_utils/src/napi_utils.cpp b/utils/napi_utils/src/napi_utils.cpp index 47afe60d7..6ffcc9244 100644 --- a/utils/napi_utils/src/napi_utils.cpp +++ b/utils/napi_utils/src/napi_utils.cpp @@ -33,6 +33,10 @@ #include "netstack_log.h" #include "node_api.h" +#include "bundle_mgr_interface.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + namespace OHOS::NetStack::NapiUtils { static constexpr const char *GLOBAL_JSON = "JSON"; @@ -948,4 +952,46 @@ bool IsEnvValid(napi_env env) } return true; } + + +bool IsDebugMode() +{ + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + NETSTACK_LOGE("IsDebugMode failed to get system ability mgr."); + return false; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (remoteObject == nullptr) { + NETSTACK_LOGE("IsDebugMode failed to get bundle manager proxy."); + return false; + } + + sptr bundleMgrProxy = iface_cast(remoteObject); + if (bundleMgrProxy == nullptr) { + NETSTACK_LOGE("IsDebugMode failed to get bundle manager proxy."); + return false; + } + + AppExecFwk::BundleInfo bundleInfo; + constexpr auto flag = static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION); + const auto res = bundleMgrProxy->GetBundleInfoForSelf(flag, bundleInfo); + NETSTACK_LOGI("IsDebugMode GetBundleInfoForSelf res = %{public}d", res); + + const auto appProvisionType = bundleInfo.applicationInfo.appProvisionType; + NETSTACK_LOGI("IsDebugMode appProvisionType = %{public}s", appProvisionType.c_str()); + + return (appProvisionType == "debug") ? true : false; +} + +std::string removeUrlParameters(const std::string& url) { + size_t questionMarkPos = url.find('?'); + if (questionMarkPos == std::string::npos) { + return url; + } + return url.substr(0, questionMarkPos); +} + } // namespace OHOS::NetStack::NapiUtils -- Gitee