From f45e0616227ca00429b993dfefe61f2ff2159aa9 Mon Sep 17 00:00:00 2001 From: hhchinasoft Date: Tue, 30 Nov 2021 09:48:00 +0800 Subject: [PATCH] clean code check Signed-off-by: hhchinasoft --- frameworks/js/napi/http/include/http_request.h | 6 +++--- .../http/include/http_request_options_context.h | 2 +- frameworks/js/napi/http/src/http_request.cpp | 7 +++++-- frameworks/js/napi/http/src/napi_util.cpp | 4 ---- .../js/napi/websocket/include/websocket_napi.h | 1 - .../js/napi/websocket/src/websocket_napi.cpp | 2 -- interfaces/kits/js/basic.d.ts | 16 ---------------- 7 files changed, 9 insertions(+), 29 deletions(-) delete mode 100644 interfaces/kits/js/basic.d.ts diff --git a/frameworks/js/napi/http/include/http_request.h b/frameworks/js/napi/http/include/http_request.h index 07097621c..9041b8359 100644 --- a/frameworks/js/napi/http/include/http_request.h +++ b/frameworks/js/napi/http/include/http_request.h @@ -16,15 +16,15 @@ #ifndef HTTP_REQUEST_H #define HTTP_REQUEST_H +#include +#include + #include "base/security/deviceauth/deps_adapter/os_adapter/interfaces/linux/hc_log.h" #include "http_request_options_context.h" #include "netmgr_log_wrapper.h" #include -#include -#include - #define HTTP_CURL_EASY_SET_OPTION(handle, opt, data) \ do { \ CURLcode result = curl_easy_setopt(handle, opt, data); \ diff --git a/frameworks/js/napi/http/include/http_request_options_context.h b/frameworks/js/napi/http/include/http_request_options_context.h index a2cd327d5..db177107d 100644 --- a/frameworks/js/napi/http/include/http_request_options_context.h +++ b/frameworks/js/napi/http/include/http_request_options_context.h @@ -149,7 +149,7 @@ private: int32_t ifModifiedSince_ = 0; bool usingCache_ = true; int32_t fixedLengthStreamingMode_ = -1; - std::string url_ = ""; + std::string url_ = ""; HttpResponse responseData_; std::string cafile_; }; diff --git a/frameworks/js/napi/http/src/http_request.cpp b/frameworks/js/napi/http/src/http_request.cpp index ef5965be3..3a89966af 100644 --- a/frameworks/js/napi/http/src/http_request.cpp +++ b/frameworks/js/napi/http/src/http_request.cpp @@ -24,6 +24,7 @@ namespace OHOS { namespace NetManagerStandard { std::string URL_SEPARATOR = "?"; std::string URL_DELIMITER = "&"; +constexpr int32_t HEADER_OFFSET = 2; HttpRequest::HttpRequest() { @@ -71,7 +72,8 @@ void HttpRequest::SetHeaders(std::string headersStr) if (std::string::npos == posColon) { headers_["null"] = "[\"" + header + "\"]"; } else { - headers_["\"" + header.substr(0, posColon) + "\""] = "[\"" + header.substr(posColon + 2) + "\"]"; + headers_["\"" + header.substr(0, posColon) + "\""] = "[\"" + header.substr(posColon + + HEADER_OFFSET) + "\"]"; } headersStr = headersStr.substr(posSeparator + 1); posSeparator = headersStr.find(separator); @@ -288,7 +290,8 @@ void HttpRequest::EmitHeader(HttpRequest *obj, const std::string &header) callbackValues[1] = object; napi_value callbackResult = nullptr; - napi_call_function(env, undefine, callbackFunc, 2, callbackValues, &callbackResult); + napi_call_function(env, undefine, callbackFunc, std::size(callbackValues), callbackValues, + &callbackResult); napi_close_handle_scope(env, scope); napi_delete_reference(env, listenerIterator->callbackRef_); break; diff --git a/frameworks/js/napi/http/src/napi_util.cpp b/frameworks/js/napi/http/src/napi_util.cpp index e8f9e1f5b..f06920058 100644 --- a/frameworks/js/napi/http/src/napi_util.cpp +++ b/frameworks/js/napi/http/src/napi_util.cpp @@ -16,10 +16,7 @@ #include "napi_util.h" #include -#include #include -#include -#include #include "netmgr_log_wrapper.h" @@ -158,7 +155,6 @@ std::string NapiUtil::GetStringFromValue(napi_env env, napi_value value) char msgChars[MAX_TEXT_LENGTH] = {0}; size_t msgLength = 0; NAPI_CALL_BASE(env, napi_get_value_string_utf8(env, value, msgChars, MAX_TEXT_LENGTH, &msgLength), ""); - NETMGR_LOGD("NapiUtil GetStringFromValue msgLength = %{public}d", msgLength); if (msgLength > 0) { return std::string(msgChars, 0, msgLength); } else { diff --git a/frameworks/js/napi/websocket/include/websocket_napi.h b/frameworks/js/napi/websocket/include/websocket_napi.h index 4dfdaf199..dc70feb7e 100644 --- a/frameworks/js/napi/websocket/include/websocket_napi.h +++ b/frameworks/js/napi/websocket/include/websocket_napi.h @@ -21,7 +21,6 @@ namespace OHOS { namespace NetManagerStandard { - } // namespace NetManagerStandard } // namespace OHOS #endif // WEBSOCKET_NAPI_H \ No newline at end of file diff --git a/frameworks/js/napi/websocket/src/websocket_napi.cpp b/frameworks/js/napi/websocket/src/websocket_napi.cpp index 0097029c4..08db278c9 100644 --- a/frameworks/js/napi/websocket/src/websocket_napi.cpp +++ b/frameworks/js/napi/websocket/src/websocket_napi.cpp @@ -18,7 +18,5 @@ namespace OHOS { namespace NetManagerStandard { -//DEFINE_NETMANAGER_NAPI_LOG_LABEL("WebSocketNapi"); - } // namespace NetManagerStandard } // namespace OHOS diff --git a/interfaces/kits/js/basic.d.ts b/interfaces/kits/js/basic.d.ts deleted file mode 100644 index 09a3400c3..000000000 --- a/interfaces/kits/js/basic.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -// basic.d.ts -export interface AsyncCallback { - (err: BusinessError, data: T): void; -} - -export interface BusinessError extends Error { - code: number; -} - -export interface ErrorCallback { - (err: BusinessError): void; -} - -export interface Callback { - (data: T): void; -} -- Gitee