From 054258df7e74f123c4b5ec2648b7aad98d51c010 Mon Sep 17 00:00:00 2001 From: BianYafei Date: Mon, 2 Jan 2023 13:46:32 +0800 Subject: [PATCH 1/9] =?UTF-8?q?http=20proxy=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BianYafei Change-Id: Ib3c816f4fe449c444528205b2ff61226479e7001 --- frameworks/js/napi/http/BUILD.gn | 1 + .../napi/http/http_exec/include/http_exec.h | 4 + .../js/napi/http/http_exec/src/http_exec.cpp | 63 ++++++- utils/BUILD.gn | 5 +- utils/common_utils/include/base64_utils.h | 26 +++ utils/common_utils/src/base64_utils.cpp | 177 ++++++++++++++++++ 6 files changed, 270 insertions(+), 6 deletions(-) create mode 100644 utils/common_utils/include/base64_utils.h create mode 100644 utils/common_utils/src/base64_utils.cpp diff --git a/frameworks/js/napi/http/BUILD.gn b/frameworks/js/napi/http/BUILD.gn index 3fd834027..8005893d3 100644 --- a/frameworks/js/napi/http/BUILD.gn +++ b/frameworks/js/napi/http/BUILD.gn @@ -85,6 +85,7 @@ ohos_shared_library("http") { external_deps = [ "c_utils:utils", "hiviewdfx_hilog_native:libhilog", + "init:libbegetutil", "napi:ace_napi", ] } diff --git a/frameworks/js/napi/http/http_exec/include/http_exec.h b/frameworks/js/napi/http/http_exec/include/http_exec.h index b4f7533ad..d6e7db82e 100644 --- a/frameworks/js/napi/http/http_exec/include/http_exec.h +++ b/frameworks/js/napi/http/http_exec/include/http_exec.h @@ -103,6 +103,10 @@ private: static void ReadRespond(); + static void GetHttpProxyInfo(std::string &host, int32_t &port, std::string exclusions); + + static bool IsGetUrlExcluded(const std::string &url, const std::string &exclusions); + struct StaticVariable { StaticVariable() : curlMulti(nullptr), initialized(false), runThread(true) {} 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 444ddad3d..5981555cd 100644 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -19,6 +19,9 @@ #include #include +#include "parameter.h" + +#include "base64_utils.h" #include "cache_proxy.h" #include "constant.h" #include "event_list.h" @@ -46,6 +49,14 @@ namespace OHOS::NetStack { static constexpr size_t MAX_LIMIT = 5 * 1024 * 1024; static constexpr int CURL_TIMEOUT_MS = 50; static constexpr int CURL_HANDLE_NUM = 10; +static constexpr int32_t SYSPARA_MAX_SIZE = 128; +static constexpr const char *EXCLUSIONS_SPLIT_SYMBOL = ","; +static constexpr const char *DEFAULT_HTTP_PROXY_HOST = "NONE"; +static constexpr const char *DEFAULT_HTTP_PROXY_PORT = "0"; +static constexpr const char *DEFAULT_HTTP_PROXY_EXCLUSION_LIST = "NONE"; +static constexpr const char *HTTP_PROXY_HOST_KEY = "persist.netmanager_base.http_proxy.host"; +static constexpr const char *HTTP_PROXY_PORT_KEY = "persist.netmanager_base.http_proxy.port"; +static constexpr const char *HTTP_PROXY_EXCLUSIONS_KEY = "persist.netmanager_base.http_proxy.exclusion_list"; bool HttpExec::AddCurlHandle(CURL *handle, RequestContext *context) { if (handle == nullptr || staticVariable_.curlMulti == nullptr) { @@ -347,6 +358,43 @@ void HttpExec::ReadRespond() } } +void HttpExec::GetHttpProxyInfo(std::string &host, int32_t &port, std::string exclusions) +{ + char httpProxyHost[SYSPARA_MAX_SIZE] = {0}; + char httpProxyPort[SYSPARA_MAX_SIZE] = {0}; + char httpProxyExclusions[SYSPARA_MAX_SIZE] = {0}; + GetParameter(HTTP_PROXY_HOST_KEY, DEFAULT_HTTP_PROXY_HOST, httpProxyHost, sizeof(httpProxyHost)); + GetParameter(HTTP_PROXY_PORT_KEY, DEFAULT_HTTP_PROXY_PORT, httpProxyPort, sizeof(httpProxyPort)); + GetParameter(HTTP_PROXY_EXCLUSIONS_KEY, DEFAULT_HTTP_PROXY_EXCLUSION_LIST, httpProxyExclusions, + sizeof(httpProxyExclusions)); + host = Base64::Decode(httpProxyHost); + exclusions = httpProxyExclusions; + port = std::atoi(httpProxyPort); +} + +bool HttpExec::IsGetUrlExcluded(const std::string &url, const std::string &exclusions) +{ + if (exclusions.empty()) { + return false; + } + size_t startPos = 0; + size_t searchePos = exclusions.find(EXCLUSIONS_SPLIT_SYMBOL); + std::string exclusion; + while (searchePos != std::string::npos) { + exclusion = exclusions.substr(startPos, (searchePos - startPos)); + if (url.find(exclusion) != std::string::npos) { + return true; + } + startPos = searchePos + 1; + searchePos = exclusions.find(EXCLUSIONS_SPLIT_SYMBOL, startPos); + } + exclusion = exclusions.substr(startPos, (exclusions.size() - startPos)); + if (url.find(exclusion) != std::string::npos) { + return true; + } + return false; +} + bool HttpExec::Initialize() { std::lock_guard lock(staticVariable_.mutex); @@ -402,14 +450,19 @@ bool HttpExec::SetOption(CURL *curl, RequestContext *context, struct curl_slist /* first #undef CURL_DISABLE_COOKIES in curl config */ NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_COOKIEFILE, "", context); -#if NETSTACK_USE_PROXY - NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXY, NETSTACK_PROXY_URL_PORT, context); - NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXYTYPE, NETSTACK_PROXY_TYPE, context); - NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_HTTPPROXYTUNNEL, 1L, context); + std::string host; + int32_t port = 0; + std::string exclusions; + GetHttpProxyInfo(host, port, exclusions); + if (!host.empty() && !IsGetUrlExcluded(context->options.GetUrl(), exclusions)) { + NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXY, host.c_str(), context); + NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXYPORT, port, context); + NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP, context); + NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_HTTPPROXYTUNNEL, 1L, context); + } #ifdef NETSTACK_PROXY_PASS NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXYUSERPWD, NETSTACK_PROXY_PASS, context); #endif // NETSTACK_PROXY_PASS -#endif // NETSTACK_USE_PROXY #if NO_SSL_CERTIFICATION // in real life, you should buy a ssl certification and rename it to /etc/ssl/cert.pem diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 976ce8fe3..f55f27376 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -28,7 +28,10 @@ config("stack_utils_common_public_config") { } ohos_shared_library("stack_utils_common") { - sources = [ "common_utils/src/netstack_common_utils.cpp" ] + sources = [ + "common_utils/src/base64_utils.cpp", + "common_utils/src/netstack_common_utils.cpp", + ] public_configs = [ ":stack_utils_common_public_config" ] diff --git a/utils/common_utils/include/base64_utils.h b/utils/common_utils/include/base64_utils.h new file mode 100644 index 000000000..daea96f42 --- /dev/null +++ b/utils/common_utils/include/base64_utils.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NETMANAGER_BASE_BASE64_UTILS_H +#define NETMANAGER_BASE_BASE64_UTILS_H + +#include + +namespace OHOS::NetManagerStandard::Base64 { +std::string Encode(const std::string &source); +std::string Decode(const std::string &encoded); +} // namespace OHOS::NetManagerStandard::Base64 + +#endif /* NETMANAGER_BASE_BASE64_UTILS_H */ diff --git a/utils/common_utils/src/base64_utils.cpp b/utils/common_utils/src/base64_utils.cpp new file mode 100644 index 000000000..9074026af --- /dev/null +++ b/utils/common_utils/src/base64_utils.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "base64_utils.h" + +namespace OHOS::NetManagerStandard::Base64 { +static std::string BASE64_CHARS = /* NOLINT */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; + +static constexpr const uint32_t CHAR_ARRAY_LENGTH_THREE = 3; +static constexpr const uint32_t CHAR_ARRAY_LENGTH_FOUR = 4; + +enum BASE64_ENCODE_CONSTANT : uint8_t { + BASE64_ENCODE_MASK1 = 0xfc, + BASE64_ENCODE_MASK2 = 0x03, + BASE64_ENCODE_MASK3 = 0x0f, + BASE64_ENCODE_MASK4 = 0x3f, + BASE64_ENCODE_MASK5 = 0xf0, + BASE64_ENCODE_MASK6 = 0xc0, + BASE64_ENCODE_OFFSET2 = 2, + BASE64_ENCODE_OFFSET4 = 4, + BASE64_ENCODE_OFFSET6 = 6, + BASE64_ENCODE_INDEX0 = 0, + BASE64_ENCODE_INDEX1 = 1, + BASE64_ENCODE_INDEX2 = 2, +}; + +enum BASE64_DECODE_CONSTANT : uint8_t { + BASE64_DECODE_MASK1 = 0x30, + BASE64_DECODE_MASK2 = 0xf, + BASE64_DECODE_MASK3 = 0x3c, + BASE64_DECODE_MASK4 = 0x3, + BASE64_DECODE_OFFSET2 = 2, + BASE64_DECODE_OFFSET4 = 4, + BASE64_DECODE_OFFSET6 = 6, + BASE64_DECODE_INDEX0 = 0, + BASE64_DECODE_INDEX1 = 1, + BASE64_DECODE_INDEX2 = 2, + BASE64_DECODE_INDEX3 = 3, +}; + +static inline bool IsBase64Char(const char c) +{ + return (isalnum(c) || (c == '+') || (c == '/')); +} + +static inline void MakeCharFour(const std::array &charArrayThree, + std::array &charArrayFour) +{ + uint8_t table[CHAR_ARRAY_LENGTH_FOUR] = { + static_cast((charArrayThree[BASE64_ENCODE_INDEX0] & BASE64_ENCODE_MASK1) >> BASE64_ENCODE_OFFSET2), + static_cast(((charArrayThree[BASE64_ENCODE_INDEX0] & BASE64_ENCODE_MASK2) << BASE64_ENCODE_OFFSET4) + + ((charArrayThree[BASE64_ENCODE_INDEX1] & BASE64_ENCODE_MASK5) >> BASE64_ENCODE_OFFSET4)), + static_cast(((charArrayThree[BASE64_ENCODE_INDEX1] & BASE64_ENCODE_MASK3) << BASE64_ENCODE_OFFSET2) + + ((charArrayThree[BASE64_ENCODE_INDEX2] & BASE64_ENCODE_MASK6) >> BASE64_ENCODE_OFFSET6)), + static_cast(charArrayThree[BASE64_ENCODE_INDEX2] & BASE64_ENCODE_MASK4), + }; + for (size_t index = 0; index < CHAR_ARRAY_LENGTH_FOUR; ++index) { + charArrayFour[index] = table[index]; + } +} + +static inline void MakeCharTree(const std::array &charArrayFour, + std::array &charArrayThree) +{ + uint8_t table[CHAR_ARRAY_LENGTH_THREE] = { + static_cast((charArrayFour[BASE64_DECODE_INDEX0] << BASE64_DECODE_OFFSET2) + + ((charArrayFour[BASE64_DECODE_INDEX1] & BASE64_DECODE_MASK1) >> BASE64_DECODE_OFFSET4)), + static_cast(((charArrayFour[BASE64_DECODE_INDEX1] & BASE64_DECODE_MASK2) << BASE64_DECODE_OFFSET4) + + ((charArrayFour[BASE64_DECODE_INDEX2] & BASE64_DECODE_MASK3) >> BASE64_DECODE_OFFSET2)), + static_cast(((charArrayFour[BASE64_DECODE_INDEX2] & BASE64_DECODE_MASK4) << BASE64_DECODE_OFFSET6) + + charArrayFour[BASE64_DECODE_INDEX3]), + }; + for (size_t index = 0; index < CHAR_ARRAY_LENGTH_THREE; ++index) { + charArrayThree[index] = table[index]; + } +} + +std::string Encode(const std::string &source) +{ + auto it = source.begin(); + std::string ret; + size_t index = 0; + std::array charArrayThree = {0}; + std::array charArrayFour = {0}; + + while (it != source.end()) { + charArrayThree[index] = *it; + ++index; + ++it; + if (index != CHAR_ARRAY_LENGTH_THREE) { + continue; + } + MakeCharFour(charArrayThree, charArrayFour); + for (auto idx : charArrayFour) { + ret += BASE64_CHARS[idx]; + } + index = 0; + } + if (index == 0) { + return ret; + } + + for (auto i = index; i < CHAR_ARRAY_LENGTH_THREE; ++i) { + charArrayThree[i] = 0; + } + MakeCharFour(charArrayThree, charArrayFour); + + for (size_t i = 0; i < index + 1; ++i) { + ret += BASE64_CHARS[charArrayFour[i]]; + } + + while (index < CHAR_ARRAY_LENGTH_THREE) { + ret += '='; + ++index; + } + return ret; +} + +std::string Decode(const std::string &encoded) +{ + auto it = encoded.begin(); + size_t index = 0; + std::array charArrayThree = {0}; + std::array charArrayFour = {0}; + std::string ret; + + while (it != encoded.end() && IsBase64Char(*it)) { + charArrayFour[index] = *it; + ++index; + ++it; + if (index != CHAR_ARRAY_LENGTH_FOUR) { + continue; + } + for (index = 0; index < CHAR_ARRAY_LENGTH_FOUR; ++index) { + charArrayFour[index] = BASE64_CHARS.find(static_cast(charArrayFour[index])); + } + MakeCharTree(charArrayFour, charArrayThree); + for (auto idx : charArrayThree) { + ret += static_cast(idx); + } + index = 0; + } + if (index == 0) { + return ret; + } + + for (auto i = index; i < CHAR_ARRAY_LENGTH_FOUR; ++i) { + charArrayFour[i] = 0; + } + for (unsigned char &i : charArrayFour) { + i = BASE64_CHARS.find(static_cast(i)); + } + MakeCharTree(charArrayFour, charArrayThree); + + for (size_t i = 0; i < index - 1; i++) { + ret += static_cast(charArrayThree[i]); + } + return ret; +} +} // namespace OHOS::NetManagerStandard::Base64 \ No newline at end of file -- Gitee From 73fb3b338a029fb6984a2c7f406b2fdb35391787 Mon Sep 17 00:00:00 2001 From: BianYafei Date: Tue, 3 Jan 2023 14:51:38 +0800 Subject: [PATCH 2/9] Correction of proxy exclude settings Signed-off-by: BianYafei Change-Id: I1315a4501f82fe1d00c87e7451bd9e4d0dde3d8d --- .clang-format | 173 ++++++++++++++++++ .../napi/http/http_exec/include/http_exec.h | 2 - .../js/napi/http/http_exec/src/http_exec.cpp | 31 +--- 3 files changed, 177 insertions(+), 29 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..71d6beaeb --- /dev/null +++ b/.clang-format @@ -0,0 +1,173 @@ +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +Language: Cpp +# BasedOnStyle: LLVM +# 访问说明符(public、private等)的偏移 +AccessModifierOffset: -4 +# 开括号(开圆括号、开尖括号、开方括号)后的对齐 +AlignAfterOpenBracket: Align +# 连续赋值时,等号对齐 +AlignConsecutiveAssignments: false +# 连续赋值时,变量名对齐 +AlignConsecutiveDeclarations: false +# 左对齐逃脱换行(使用反斜杠换行)的反斜杠 +AlignEscapedNewlinesLeft: true +# 水平对齐二元和三元表达式的操作数 +AlignOperands: true +# 对齐连续的尾随的注释 +AlignTrailingComments: true +# 允许函数声明的所有参数在放在下一行 +AllowAllParametersOfDeclarationOnNextLine: false +# 允许短的块放在同一行 +AllowShortBlocksOnASingleLine: false +# 允许短的case标签放在同一行 +AllowShortCaseLabelsOnASingleLine: false +# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All +AllowShortFunctionsOnASingleLine: Empty +# 允许短的if语句保持在同一行 +AllowShortIfStatementsOnASingleLine: false +# 允许短的循环保持在同一行 +AllowShortLoopsOnASingleLine: false +# 总是在定义返回类型后换行(deprecated) +AlwaysBreakAfterDefinitionReturnType: None +# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数), +# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义) +AlwaysBreakAfterReturnType: None +# 总是在多行string字面量前换行 +AlwaysBreakBeforeMultilineStrings: true +# 总是在template声明后换行 +AlwaysBreakTemplateDeclarations: false +# false表示函数实参要么都在同一行,要么都各自一行 +BinPackArguments: true +# false表示所有形参要么都在同一行,要么都各自一行 +BinPackParameters: true +# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效 +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false +# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行) +BreakBeforeBinaryOperators: None +# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似), +# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似), +# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom +# 注:这里认为语句块也属于函数 +BreakBeforeBraces: Custom +# 在三元运算符前换行 +BreakBeforeTernaryOperators: true +# 在构造函数的初始化列表的逗号前换行 +BreakConstructorInitializersBeforeComma: false +# 每行字符的限制,0表示没有限制 +ColumnLimit: 120 +# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变 +CommentPragmas: "^ IWYU pragma:" +# 构造函数的初始化列表要么都在同一行,要么都各自一行 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +# 构造函数的初始化列表的缩进宽度 +ConstructorInitializerIndentWidth: 4 +# 延续的行的缩进宽度 +ContinuationIndentWidth: 4 +# 去除C++11的列表初始化的大括号{后和}前的空格 +Cpp11BracedListStyle: true +# 继承最常用的指针和引用的对齐方式 +DerivePointerAlignment: false +# 关闭格式化 +DisableFormat: false +# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental) +ExperimentalAutoDetectBinPacking: false +# 需要被解读为foreach循环而不是函数调用的宏 +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +# 对#include进行排序,匹配了某正则表达式的#include拥有对应的优先级,匹配不到的则默认优先级为INT_MAX(优先级越小排序越靠前), +# 可以定义负数优先级从而保证某些#include永远在最前面 +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + - Regex: ".*" + Priority: 1 +# 缩进case标签 +IndentCaseLabels: true +# 缩进宽度 +IndentWidth: 4 +# 函数返回类型换行时,缩进函数声明或函数定义的函数名 +IndentWrappedFunctionNames: true +# 保留在块开始处的空行 +KeepEmptyLinesAtTheStartOfBlocks: true +# 开始一个块的宏的正则表达式 +MacroBlockBegin: "" +# 结束一个块的宏的正则表达式 +MacroBlockEnd: "" +# 连续空行的最大数量 +MaxEmptyLinesToKeep: 1 +# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All +NamespaceIndentation: None +# 使用ObjC块时缩进宽度 +ObjCBlockIndentWidth: 4 +# 在ObjC的@property后添加一个空格 +ObjCSpaceAfterProperty: false +# 在ObjC的protocol列表前添加一个空格 +ObjCSpaceBeforeProtocolList: true +# 在call(后对函数调用换行的penalty +PenaltyBreakBeforeFirstCallParameter: 19 +# 在一个注释中引入换行的penalty +PenaltyBreakComment: 300 +# 第一次在<<前换行的penalty +PenaltyBreakFirstLessLess: 120 +# 在一个字符串字面量中引入换行的penalty +PenaltyBreakString: 1000 +# 对于每个在行字符数限制之外的字符的penalty +PenaltyExcessCharacter: 1000000 +# 将函数的返回类型放到它自己的行的penalty +PenaltyReturnTypeOnItsOwnLine: 60 +# 指针和引用的对齐: Left, Right, Middle +PointerAlignment: Right +# 允许重新排版注释 +ReflowComments: true +# 允许排序#include +SortIncludes: false +# 在C风格类型转换后添加空格 +SpaceAfterCStyleCast: false +# 在赋值运算符之前添加空格 +SpaceBeforeAssignmentOperators: true +# 开圆括号之前添加一个空格: Never, ControlStatements, Always +SpaceBeforeParens: ControlStatements +# 在空的圆括号中添加空格 +SpaceInEmptyParentheses: false +# 在尾随的评论前添加的空格数(只适用于//) +SpacesBeforeTrailingComments: 1 +# 在尖括号的<后和>前添加空格 +SpacesInAngles: false +# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格 +SpacesInContainerLiterals: true +# 在C风格类型转换的括号中添加空格 +SpacesInCStyleCastParentheses: false +# 在圆括号的(后和)前添加空格 +SpacesInParentheses: false +# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响 +SpacesInSquareBrackets: false +# 标准: Cpp03, Cpp11, Auto +Standard: Cpp11 +# tab宽度 +TabWidth: 4 +# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always +UseTab: Never \ No newline at end of file diff --git a/frameworks/js/napi/http/http_exec/include/http_exec.h b/frameworks/js/napi/http/http_exec/include/http_exec.h index d6e7db82e..ffbdea49a 100644 --- a/frameworks/js/napi/http/http_exec/include/http_exec.h +++ b/frameworks/js/napi/http/http_exec/include/http_exec.h @@ -105,8 +105,6 @@ private: static void GetHttpProxyInfo(std::string &host, int32_t &port, std::string exclusions); - static bool IsGetUrlExcluded(const std::string &url, const std::string &exclusions); - struct StaticVariable { StaticVariable() : curlMulti(nullptr), initialized(false), runThread(true) {} 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 5981555cd..1d36fc33a 100644 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -50,10 +50,9 @@ static constexpr size_t MAX_LIMIT = 5 * 1024 * 1024; static constexpr int CURL_TIMEOUT_MS = 50; static constexpr int CURL_HANDLE_NUM = 10; static constexpr int32_t SYSPARA_MAX_SIZE = 128; -static constexpr const char *EXCLUSIONS_SPLIT_SYMBOL = ","; -static constexpr const char *DEFAULT_HTTP_PROXY_HOST = "NONE"; +static constexpr const char *DEFAULT_HTTP_PROXY_HOST = ""; static constexpr const char *DEFAULT_HTTP_PROXY_PORT = "0"; -static constexpr const char *DEFAULT_HTTP_PROXY_EXCLUSION_LIST = "NONE"; +static constexpr const char *DEFAULT_HTTP_PROXY_EXCLUSION_LIST = ""; static constexpr const char *HTTP_PROXY_HOST_KEY = "persist.netmanager_base.http_proxy.host"; static constexpr const char *HTTP_PROXY_PORT_KEY = "persist.netmanager_base.http_proxy.port"; static constexpr const char *HTTP_PROXY_EXCLUSIONS_KEY = "persist.netmanager_base.http_proxy.exclusion_list"; @@ -372,29 +371,6 @@ void HttpExec::GetHttpProxyInfo(std::string &host, int32_t &port, std::string ex port = std::atoi(httpProxyPort); } -bool HttpExec::IsGetUrlExcluded(const std::string &url, const std::string &exclusions) -{ - if (exclusions.empty()) { - return false; - } - size_t startPos = 0; - size_t searchePos = exclusions.find(EXCLUSIONS_SPLIT_SYMBOL); - std::string exclusion; - while (searchePos != std::string::npos) { - exclusion = exclusions.substr(startPos, (searchePos - startPos)); - if (url.find(exclusion) != std::string::npos) { - return true; - } - startPos = searchePos + 1; - searchePos = exclusions.find(EXCLUSIONS_SPLIT_SYMBOL, startPos); - } - exclusion = exclusions.substr(startPos, (exclusions.size() - startPos)); - if (url.find(exclusion) != std::string::npos) { - return true; - } - return false; -} - bool HttpExec::Initialize() { std::lock_guard lock(staticVariable_.mutex); @@ -454,9 +430,10 @@ bool HttpExec::SetOption(CURL *curl, RequestContext *context, struct curl_slist int32_t port = 0; std::string exclusions; GetHttpProxyInfo(host, port, exclusions); - if (!host.empty() && !IsGetUrlExcluded(context->options.GetUrl(), exclusions)) { + if (!host.empty()) { NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXY, host.c_str(), context); NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXYPORT, port, context); + NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_NOPROXY, exclusions.c_str(), context); NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP, context); NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_HTTPPROXYTUNNEL, 1L, context); } -- Gitee From 388f9ef5288c2e5a020400ffbaeb94c898bfb2bb Mon Sep 17 00:00:00 2001 From: BianYafei Date: Tue, 3 Jan 2023 14:53:47 +0800 Subject: [PATCH 3/9] delete .clang-format Signed-off-by: BianYafei Change-Id: Iaa7e44204bd7a63cf9a0921cd19d32fb37c5612d --- .clang-format | 173 -------------------------------------------------- 1 file changed, 173 deletions(-) delete mode 100644 .clang-format diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 71d6beaeb..000000000 --- a/.clang-format +++ /dev/null @@ -1,173 +0,0 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -Language: Cpp -# BasedOnStyle: LLVM -# 访问说明符(public、private等)的偏移 -AccessModifierOffset: -4 -# 开括号(开圆括号、开尖括号、开方括号)后的对齐 -AlignAfterOpenBracket: Align -# 连续赋值时,等号对齐 -AlignConsecutiveAssignments: false -# 连续赋值时,变量名对齐 -AlignConsecutiveDeclarations: false -# 左对齐逃脱换行(使用反斜杠换行)的反斜杠 -AlignEscapedNewlinesLeft: true -# 水平对齐二元和三元表达式的操作数 -AlignOperands: true -# 对齐连续的尾随的注释 -AlignTrailingComments: true -# 允许函数声明的所有参数在放在下一行 -AllowAllParametersOfDeclarationOnNextLine: false -# 允许短的块放在同一行 -AllowShortBlocksOnASingleLine: false -# 允许短的case标签放在同一行 -AllowShortCaseLabelsOnASingleLine: false -# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All -AllowShortFunctionsOnASingleLine: Empty -# 允许短的if语句保持在同一行 -AllowShortIfStatementsOnASingleLine: false -# 允许短的循环保持在同一行 -AllowShortLoopsOnASingleLine: false -# 总是在定义返回类型后换行(deprecated) -AlwaysBreakAfterDefinitionReturnType: None -# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数), -# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义) -AlwaysBreakAfterReturnType: None -# 总是在多行string字面量前换行 -AlwaysBreakBeforeMultilineStrings: true -# 总是在template声明后换行 -AlwaysBreakTemplateDeclarations: false -# false表示函数实参要么都在同一行,要么都各自一行 -BinPackArguments: true -# false表示所有形参要么都在同一行,要么都各自一行 -BinPackParameters: true -# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效 -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: true - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false -# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行) -BreakBeforeBinaryOperators: None -# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似), -# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似), -# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom -# 注:这里认为语句块也属于函数 -BreakBeforeBraces: Custom -# 在三元运算符前换行 -BreakBeforeTernaryOperators: true -# 在构造函数的初始化列表的逗号前换行 -BreakConstructorInitializersBeforeComma: false -# 每行字符的限制,0表示没有限制 -ColumnLimit: 120 -# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变 -CommentPragmas: "^ IWYU pragma:" -# 构造函数的初始化列表要么都在同一行,要么都各自一行 -ConstructorInitializerAllOnOneLineOrOnePerLine: true -# 构造函数的初始化列表的缩进宽度 -ConstructorInitializerIndentWidth: 4 -# 延续的行的缩进宽度 -ContinuationIndentWidth: 4 -# 去除C++11的列表初始化的大括号{后和}前的空格 -Cpp11BracedListStyle: true -# 继承最常用的指针和引用的对齐方式 -DerivePointerAlignment: false -# 关闭格式化 -DisableFormat: false -# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental) -ExperimentalAutoDetectBinPacking: false -# 需要被解读为foreach循环而不是函数调用的宏 -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -# 对#include进行排序,匹配了某正则表达式的#include拥有对应的优先级,匹配不到的则默认优先级为INT_MAX(优先级越小排序越靠前), -# 可以定义负数优先级从而保证某些#include永远在最前面 -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - - Regex: '^(<|"(gtest|isl|json)/)' - Priority: 3 - - Regex: ".*" - Priority: 1 -# 缩进case标签 -IndentCaseLabels: true -# 缩进宽度 -IndentWidth: 4 -# 函数返回类型换行时,缩进函数声明或函数定义的函数名 -IndentWrappedFunctionNames: true -# 保留在块开始处的空行 -KeepEmptyLinesAtTheStartOfBlocks: true -# 开始一个块的宏的正则表达式 -MacroBlockBegin: "" -# 结束一个块的宏的正则表达式 -MacroBlockEnd: "" -# 连续空行的最大数量 -MaxEmptyLinesToKeep: 1 -# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All -NamespaceIndentation: None -# 使用ObjC块时缩进宽度 -ObjCBlockIndentWidth: 4 -# 在ObjC的@property后添加一个空格 -ObjCSpaceAfterProperty: false -# 在ObjC的protocol列表前添加一个空格 -ObjCSpaceBeforeProtocolList: true -# 在call(后对函数调用换行的penalty -PenaltyBreakBeforeFirstCallParameter: 19 -# 在一个注释中引入换行的penalty -PenaltyBreakComment: 300 -# 第一次在<<前换行的penalty -PenaltyBreakFirstLessLess: 120 -# 在一个字符串字面量中引入换行的penalty -PenaltyBreakString: 1000 -# 对于每个在行字符数限制之外的字符的penalty -PenaltyExcessCharacter: 1000000 -# 将函数的返回类型放到它自己的行的penalty -PenaltyReturnTypeOnItsOwnLine: 60 -# 指针和引用的对齐: Left, Right, Middle -PointerAlignment: Right -# 允许重新排版注释 -ReflowComments: true -# 允许排序#include -SortIncludes: false -# 在C风格类型转换后添加空格 -SpaceAfterCStyleCast: false -# 在赋值运算符之前添加空格 -SpaceBeforeAssignmentOperators: true -# 开圆括号之前添加一个空格: Never, ControlStatements, Always -SpaceBeforeParens: ControlStatements -# 在空的圆括号中添加空格 -SpaceInEmptyParentheses: false -# 在尾随的评论前添加的空格数(只适用于//) -SpacesBeforeTrailingComments: 1 -# 在尖括号的<后和>前添加空格 -SpacesInAngles: false -# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格 -SpacesInContainerLiterals: true -# 在C风格类型转换的括号中添加空格 -SpacesInCStyleCastParentheses: false -# 在圆括号的(后和)前添加空格 -SpacesInParentheses: false -# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响 -SpacesInSquareBrackets: false -# 标准: Cpp03, Cpp11, Auto -Standard: Cpp11 -# tab宽度 -TabWidth: 4 -# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always -UseTab: Never \ No newline at end of file -- Gitee From be708132d98c964e43da5791d5ca9d2fd1e6d337 Mon Sep 17 00:00:00 2001 From: BianYafei Date: Wed, 4 Jan 2023 19:23:29 +0800 Subject: [PATCH 4/9] bug fix Signed-off-by: BianYafei Change-Id: Iccc1661b4920a8ead596d8d81826bf944c8c09a9 --- .../napi/http/http_exec/include/http_exec.h | 2 +- .../js/napi/http/http_exec/src/http_exec.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/frameworks/js/napi/http/http_exec/include/http_exec.h b/frameworks/js/napi/http/http_exec/include/http_exec.h index ffbdea49a..4efed4edb 100644 --- a/frameworks/js/napi/http/http_exec/include/http_exec.h +++ b/frameworks/js/napi/http/http_exec/include/http_exec.h @@ -103,7 +103,7 @@ private: static void ReadRespond(); - static void GetHttpProxyInfo(std::string &host, int32_t &port, std::string exclusions); + static void GetHttpProxyInfo(std::string &host, int32_t &port, std::string &exclusions); struct StaticVariable { StaticVariable() : curlMulti(nullptr), initialized(false), runThread(true) {} 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 1d36fc33a..fb898134d 100644 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -50,9 +50,9 @@ static constexpr size_t MAX_LIMIT = 5 * 1024 * 1024; static constexpr int CURL_TIMEOUT_MS = 50; static constexpr int CURL_HANDLE_NUM = 10; static constexpr int32_t SYSPARA_MAX_SIZE = 128; -static constexpr const char *DEFAULT_HTTP_PROXY_HOST = ""; +static constexpr const char *DEFAULT_HTTP_PROXY_HOST = "NONE"; static constexpr const char *DEFAULT_HTTP_PROXY_PORT = "0"; -static constexpr const char *DEFAULT_HTTP_PROXY_EXCLUSION_LIST = ""; +static constexpr const char *DEFAULT_HTTP_PROXY_EXCLUSION_LIST = "NONE"; static constexpr const char *HTTP_PROXY_HOST_KEY = "persist.netmanager_base.http_proxy.host"; static constexpr const char *HTTP_PROXY_PORT_KEY = "persist.netmanager_base.http_proxy.port"; static constexpr const char *HTTP_PROXY_EXCLUSIONS_KEY = "persist.netmanager_base.http_proxy.exclusion_list"; @@ -357,7 +357,7 @@ void HttpExec::ReadRespond() } } -void HttpExec::GetHttpProxyInfo(std::string &host, int32_t &port, std::string exclusions) +void HttpExec::GetHttpProxyInfo(std::string &host, int32_t &port, std::string &exclusions) { char httpProxyHost[SYSPARA_MAX_SIZE] = {0}; char httpProxyPort[SYSPARA_MAX_SIZE] = {0}; @@ -366,8 +366,17 @@ void HttpExec::GetHttpProxyInfo(std::string &host, int32_t &port, std::string ex GetParameter(HTTP_PROXY_PORT_KEY, DEFAULT_HTTP_PROXY_PORT, httpProxyPort, sizeof(httpProxyPort)); GetParameter(HTTP_PROXY_EXCLUSIONS_KEY, DEFAULT_HTTP_PROXY_EXCLUSION_LIST, httpProxyExclusions, sizeof(httpProxyExclusions)); + host = Base64::Decode(httpProxyHost); + if (host == DEFAULT_HTTP_PROXY_HOST) { + host = std::string(); + } + exclusions = httpProxyExclusions; + if (exclusions == DEFAULT_HTTP_PROXY_EXCLUSION_LIST) { + exclusions = std::string(); + } + port = std::atoi(httpProxyPort); } @@ -433,7 +442,9 @@ bool HttpExec::SetOption(CURL *curl, RequestContext *context, struct curl_slist if (!host.empty()) { NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXY, host.c_str(), context); NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXYPORT, port, context); - NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_NOPROXY, exclusions.c_str(), context); + if (!exclusions.empty()) { + NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_NOPROXY, exclusions.c_str(), context); + } NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP, context); NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_HTTPPROXYTUNNEL, 1L, context); } -- Gitee From 0cc2bdee56b7a642de335344affdec64f31bcf49 Mon Sep 17 00:00:00 2001 From: BianYafei Date: Wed, 11 Jan 2023 11:31:39 +0800 Subject: [PATCH 5/9] =?UTF-8?q?Http=E4=BB=A3=E7=90=86JS=20API=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BianYafei Change-Id: I3065387687b24d2258f02a01132856417cf3c4af --- .../async_context/include/request_context.h | 2 + .../async_context/src/request_context.cpp | 39 +++++++++++++++++++ .../js/napi/http/constant/include/constant.h | 6 +++ .../js/napi/http/constant/src/constant.cpp | 6 +++ .../napi/http/http_exec/include/http_exec.h | 2 +- .../js/napi/http/http_exec/src/http_exec.cpp | 11 ++++-- .../options/include/http_request_options.h | 22 +++++++++++ .../http/options/src/http_request_options.cpp | 28 ++++++++++++- interfaces/kits/js/@ohos.net.http.d.ts | 9 +++++ 9 files changed, 119 insertions(+), 6 deletions(-) diff --git a/frameworks/js/napi/http/async_context/include/request_context.h b/frameworks/js/napi/http/async_context/include/request_context.h index a13a24735..21b60482b 100644 --- a/frameworks/js/napi/http/async_context/include/request_context.h +++ b/frameworks/js/napi/http/async_context/include/request_context.h @@ -63,6 +63,8 @@ private: bool ParseExtraData(napi_value optionsValue); + void ParseUsingHttpProxy(napi_value optionsValue); + bool GetRequestBody(napi_value extraData); void UrlAndOptions(napi_value urlValue, napi_value optionsValue); diff --git a/frameworks/js/napi/http/async_context/src/request_context.cpp b/frameworks/js/napi/http/async_context/src/request_context.cpp index f44d60ab3..4473e1796 100644 --- a/frameworks/js/napi/http/async_context/src/request_context.cpp +++ b/frameworks/js/napi/http/async_context/src/request_context.cpp @@ -225,6 +225,44 @@ bool RequestContext::ParseExtraData(napi_value optionsValue) return false; } +void RequestContext::ParseUsingHttpProxy(napi_value optionsValue) +{ + if (!NapiUtils::HasNamedProperty(GetEnv(), optionsValue, HttpConstant::PARAM_KEY_USING_HTTP_PROXY)) { + NETSTACK_LOGI("Do not use http proxy"); + return; + } + napi_value httpProxyValue = + NapiUtils::GetNamedProperty(GetEnv(), optionsValue, HttpConstant::PARAM_KEY_USING_HTTP_PROXY); + napi_valuetype type = NapiUtils::GetValueType(GetEnv(), httpProxyValue); + if (type == napi_boolean) { + bool usingProxy = NapiUtils::GetBooleanFromValue(GetEnv(), httpProxyValue); + UsingHttpProxyType usingType = usingProxy ? UsingHttpProxyType::USE_DEFAULT : UsingHttpProxyType::NOT_USE; + options.SetUsingHttpProxyType(usingType); + return; + } + if (type != napi_object) { + return; + } + std::string host = NapiUtils::GetStringPropertyUtf8(GetEnv(), httpProxyValue, HttpConstant::HTTP_PROXY_KEY_HOST); + int32_t port = NapiUtils::GetInt32Property(GetEnv(), httpProxyValue, HttpConstant::HTTP_PROXY_KEY_PORT); + std::string exclusionList; + if (NapiUtils::HasNamedProperty(GetEnv(), httpProxyValue, HttpConstant::HTTP_PROXY_KEY_EXCLUSION_LIST)) { + napi_value exclusionListValue = + NapiUtils::GetNamedProperty(GetEnv(), httpProxyValue, HttpConstant::HTTP_PROXY_KEY_EXCLUSION_LIST); + uint32_t listLength = NapiUtils::GetArrayLength(GetEnv(), exclusionListValue); + for (uint32_t index = 0; index < listLength; ++index) { + napi_value exclusionValue = NapiUtils::GetArrayElement(GetEnv(), exclusionListValue, index); + std::string exclusion = NapiUtils::GetStringFromValueUtf8(GetEnv(), exclusionValue); + if (index != 0) { + exclusionList = exclusionList + HttpConstant::HTTP_PROXY_EXCLUSIONS_SEPARATOR; + } + exclusionList += exclusion; + } + } + options.SetSpecifiedHttpProxy(host, port, exclusionList); + options.SetUsingHttpProxyType(UsingHttpProxyType::USE_SPECIFIED); +} + bool RequestContext::GetRequestBody(napi_value extraData) { /* if body is empty, return false, or curl will wait for body */ @@ -274,6 +312,7 @@ void RequestContext::UrlAndOptions(napi_value urlValue, napi_value optionsValue) ParseHeader(optionsValue); ParseNumberOptions(optionsValue); + ParseUsingHttpProxy(optionsValue); /* parse extra data here to recover header */ diff --git a/frameworks/js/napi/http/constant/include/constant.h b/frameworks/js/napi/http/constant/include/constant.h index 8f9971964..01628cc6a 100644 --- a/frameworks/js/napi/http/constant/include/constant.h +++ b/frameworks/js/napi/http/constant/include/constant.h @@ -105,6 +105,12 @@ public: static const char *const PARAM_KEY_USING_CACHE; static const char *const PARAM_KEY_EXPECT_DATA_TYPE; static const char *const PARAM_KEY_PRIORITY; + static const char *const PARAM_KEY_USING_HTTP_PROXY; + + static const char *const HTTP_PROXY_KEY_HOST; + static const char *const HTTP_PROXY_KEY_PORT; + static const char *const HTTP_PROXY_KEY_EXCLUSION_LIST; + static const char *const HTTP_PROXY_EXCLUSIONS_SEPARATOR; static const char *const RESPONSE_KEY_RESULT; static const char *const RESPONSE_KEY_RESPONSE_CODE; diff --git a/frameworks/js/napi/http/constant/src/constant.cpp b/frameworks/js/napi/http/constant/src/constant.cpp index d1fe54a98..5309bf863 100644 --- a/frameworks/js/napi/http/constant/src/constant.cpp +++ b/frameworks/js/napi/http/constant/src/constant.cpp @@ -39,6 +39,12 @@ const char *const HttpConstant::PARAM_KEY_USING_PROTOCOL = "usingProtocol"; const char *const HttpConstant::PARAM_KEY_USING_CACHE = "usingCache"; const char *const HttpConstant::PARAM_KEY_EXPECT_DATA_TYPE = "expectDataType"; const char *const HttpConstant::PARAM_KEY_PRIORITY = "priority"; +const char *const HttpConstant::PARAM_KEY_USING_HTTP_PROXY = "usingProxy"; + +const char *const HttpConstant::HTTP_PROXY_KEY_HOST = "host"; +const char *const HttpConstant::HTTP_PROXY_KEY_PORT = "port"; +const char *const HttpConstant::HTTP_PROXY_KEY_EXCLUSION_LIST = "parsedExclusionList"; +const char *const HttpConstant::HTTP_PROXY_EXCLUSIONS_SEPARATOR = ","; const char *const HttpConstant::RESPONSE_KEY_RESULT = "result"; const char *const HttpConstant::RESPONSE_KEY_RESPONSE_CODE = "responseCode"; diff --git a/frameworks/js/napi/http/http_exec/include/http_exec.h b/frameworks/js/napi/http/http_exec/include/http_exec.h index 4efed4edb..9bb1f9603 100644 --- a/frameworks/js/napi/http/http_exec/include/http_exec.h +++ b/frameworks/js/napi/http/http_exec/include/http_exec.h @@ -103,7 +103,7 @@ private: static void ReadRespond(); - static void GetHttpProxyInfo(std::string &host, int32_t &port, std::string &exclusions); + static void GetGlobalHttpProxyInfo(std::string &host, int32_t &port, std::string &exclusions); struct StaticVariable { StaticVariable() : curlMulti(nullptr), initialized(false), runThread(true) {} 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 fb898134d..c01247215 100644 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -357,7 +357,7 @@ void HttpExec::ReadRespond() } } -void HttpExec::GetHttpProxyInfo(std::string &host, int32_t &port, std::string &exclusions) +void HttpExec::GetGlobalHttpProxyInfo(std::string &host, int32_t &port, std::string &exclusions) { char httpProxyHost[SYSPARA_MAX_SIZE] = {0}; char httpProxyPort[SYSPARA_MAX_SIZE] = {0}; @@ -435,10 +435,13 @@ bool HttpExec::SetOption(CURL *curl, RequestContext *context, struct curl_slist /* first #undef CURL_DISABLE_COOKIES in curl config */ NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_COOKIEFILE, "", context); - std::string host; + std::string host, exclusions; int32_t port = 0; - std::string exclusions; - GetHttpProxyInfo(host, port, exclusions); + if (context->options.GetUsingHttpProxyType() == UsingHttpProxyType::USE_DEFAULT) { + GetGlobalHttpProxyInfo(host, port, exclusions); + } else if (context->options.GetUsingHttpProxyType() == UsingHttpProxyType::USE_SPECIFIED) { + context->options.GetSpecifiedHttpProxy(host, port, exclusions); + } if (!host.empty()) { NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXY, host.c_str(), context); NETSTACK_CURL_EASY_SET_OPTION(curl, CURLOPT_PROXYPORT, port, context); diff --git a/frameworks/js/napi/http/options/include/http_request_options.h b/frameworks/js/napi/http/options/include/http_request_options.h index 81ac421a6..c93d43535 100644 --- a/frameworks/js/napi/http/options/include/http_request_options.h +++ b/frameworks/js/napi/http/options/include/http_request_options.h @@ -28,6 +28,12 @@ enum class HttpProtocol { HTTP_NONE, // default choose by curl }; +enum class UsingHttpProxyType { + NOT_USE, + USE_DEFAULT, + USE_SPECIFIED, +}; + class HttpRequestOptions final { public: HttpRequestOptions(); @@ -48,6 +54,10 @@ public: void SetHttpDataType(HttpDataType dataType); + void SetUsingHttpProxyType(UsingHttpProxyType type); + + void SetSpecifiedHttpProxy(const std::string &host, int32_t port, const std::string &exclusionList); + [[nodiscard]] const std::string &GetUrl() const; [[nodiscard]] const std::string &GetMethod() const; @@ -72,6 +82,10 @@ public: [[nodiscard]] uint32_t GetPriority() const; + [[nodiscard]] UsingHttpProxyType GetUsingHttpProxyType() const; + + void GetSpecifiedHttpProxy(std::string &host, int32_t &port, std::string &exclusionList); + private: std::string url_; @@ -92,6 +106,14 @@ private: HttpDataType dataType_; uint32_t priority_; + + UsingHttpProxyType usingHttpProxyType_; + + std::string httpProxyHost_; + + int32_t httpProxyPort_; + + std::string httpProxyExclusions_; }; } // namespace OHOS::NetStack diff --git a/frameworks/js/napi/http/options/src/http_request_options.cpp b/frameworks/js/napi/http/options/src/http_request_options.cpp index 96f8fd414..9e4198bee 100644 --- a/frameworks/js/napi/http/options/src/http_request_options.cpp +++ b/frameworks/js/napi/http/options/src/http_request_options.cpp @@ -30,7 +30,9 @@ HttpRequestOptions::HttpRequestOptions() connectTimeout_(HttpConstant::DEFAULT_CONNECT_TIMEOUT), usingProtocol_(HttpProtocol::HTTP_NONE), dataType_(HttpDataType::NO_DATA_TYPE), - priority_(0) + priority_(0), + usingHttpProxyType_(UsingHttpProxyType::NOT_USE), + httpProxyPort_(0) { header_[CommonUtils::ToLower(HttpConstant::HTTP_CONTENT_TYPE)] = HttpConstant::HTTP_CONTENT_TYPE_JSON; // default } @@ -148,4 +150,28 @@ uint32_t HttpRequestOptions::GetPriority() const { return priority_; } + +void HttpRequestOptions::SetUsingHttpProxyType(UsingHttpProxyType type) +{ + usingHttpProxyType_ = type; +} + +UsingHttpProxyType HttpRequestOptions::GetUsingHttpProxyType() const +{ + return usingHttpProxyType_; +} + +void HttpRequestOptions::SetSpecifiedHttpProxy(const std::string &host, int32_t port, const std::string &exclusionList) +{ + httpProxyHost_ = host; + httpProxyPort_ = port; + httpProxyExclusions_ = exclusionList; +} + +void HttpRequestOptions::GetSpecifiedHttpProxy(std::string &host, int32_t &port, std::string &exclusionList) +{ + host = httpProxyHost_; + port = httpProxyPort_; + exclusionList = httpProxyExclusions_; +} } // namespace OHOS::NetStack \ No newline at end of file diff --git a/interfaces/kits/js/@ohos.net.http.d.ts b/interfaces/kits/js/@ohos.net.http.d.ts index 66da78c59..0d6fc61d3 100644 --- a/interfaces/kits/js/@ohos.net.http.d.ts +++ b/interfaces/kits/js/@ohos.net.http.d.ts @@ -14,6 +14,7 @@ */ import {AsyncCallback, Callback} from "./basic"; +import connection from "./@ohos.net.connection"; /** * Provides http related APIs. @@ -22,6 +23,7 @@ import {AsyncCallback, Callback} from "./basic"; * @syscap SystemCapability.Communication.NetStack */ declare namespace http { + type HttpProxy = connection.HttpProxy; /** * Creates an HTTP request task. */ @@ -67,6 +69,13 @@ declare namespace http { * @since 9 */ usingProtocol?: HttpProtocol; // default is automatically specified by the system. + /** + * If this parameter is set as type of boolean, the system will use default proxy or not use proxy. + * If this parameter is set as type of HttpProxy, the system will use the specified HttpProxy. + * + * @since 10 + */ + usingProxy?: boolean | HttpProxy; // default is false. } export interface HttpRequest { -- Gitee From 22dca2d2bab7a0cfcefe631d01503983a160d0f8 Mon Sep 17 00:00:00 2001 From: BianYafei Date: Wed, 11 Jan 2023 13:44:58 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BianYafei Change-Id: Ic999427afbcec14fe2c29f2f4d384713c9338fee --- utils/BUILD.gn | 5 +- utils/common_utils/include/base64_utils.h | 26 ---- utils/common_utils/src/base64_utils.cpp | 177 ---------------------- 3 files changed, 1 insertion(+), 207 deletions(-) delete mode 100644 utils/common_utils/include/base64_utils.h delete mode 100644 utils/common_utils/src/base64_utils.cpp diff --git a/utils/BUILD.gn b/utils/BUILD.gn index f55f27376..976ce8fe3 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -28,10 +28,7 @@ config("stack_utils_common_public_config") { } ohos_shared_library("stack_utils_common") { - sources = [ - "common_utils/src/base64_utils.cpp", - "common_utils/src/netstack_common_utils.cpp", - ] + sources = [ "common_utils/src/netstack_common_utils.cpp" ] public_configs = [ ":stack_utils_common_public_config" ] diff --git a/utils/common_utils/include/base64_utils.h b/utils/common_utils/include/base64_utils.h deleted file mode 100644 index daea96f42..000000000 --- a/utils/common_utils/include/base64_utils.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NETMANAGER_BASE_BASE64_UTILS_H -#define NETMANAGER_BASE_BASE64_UTILS_H - -#include - -namespace OHOS::NetManagerStandard::Base64 { -std::string Encode(const std::string &source); -std::string Decode(const std::string &encoded); -} // namespace OHOS::NetManagerStandard::Base64 - -#endif /* NETMANAGER_BASE_BASE64_UTILS_H */ diff --git a/utils/common_utils/src/base64_utils.cpp b/utils/common_utils/src/base64_utils.cpp deleted file mode 100644 index 9074026af..000000000 --- a/utils/common_utils/src/base64_utils.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "base64_utils.h" - -namespace OHOS::NetManagerStandard::Base64 { -static std::string BASE64_CHARS = /* NOLINT */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; - -static constexpr const uint32_t CHAR_ARRAY_LENGTH_THREE = 3; -static constexpr const uint32_t CHAR_ARRAY_LENGTH_FOUR = 4; - -enum BASE64_ENCODE_CONSTANT : uint8_t { - BASE64_ENCODE_MASK1 = 0xfc, - BASE64_ENCODE_MASK2 = 0x03, - BASE64_ENCODE_MASK3 = 0x0f, - BASE64_ENCODE_MASK4 = 0x3f, - BASE64_ENCODE_MASK5 = 0xf0, - BASE64_ENCODE_MASK6 = 0xc0, - BASE64_ENCODE_OFFSET2 = 2, - BASE64_ENCODE_OFFSET4 = 4, - BASE64_ENCODE_OFFSET6 = 6, - BASE64_ENCODE_INDEX0 = 0, - BASE64_ENCODE_INDEX1 = 1, - BASE64_ENCODE_INDEX2 = 2, -}; - -enum BASE64_DECODE_CONSTANT : uint8_t { - BASE64_DECODE_MASK1 = 0x30, - BASE64_DECODE_MASK2 = 0xf, - BASE64_DECODE_MASK3 = 0x3c, - BASE64_DECODE_MASK4 = 0x3, - BASE64_DECODE_OFFSET2 = 2, - BASE64_DECODE_OFFSET4 = 4, - BASE64_DECODE_OFFSET6 = 6, - BASE64_DECODE_INDEX0 = 0, - BASE64_DECODE_INDEX1 = 1, - BASE64_DECODE_INDEX2 = 2, - BASE64_DECODE_INDEX3 = 3, -}; - -static inline bool IsBase64Char(const char c) -{ - return (isalnum(c) || (c == '+') || (c == '/')); -} - -static inline void MakeCharFour(const std::array &charArrayThree, - std::array &charArrayFour) -{ - uint8_t table[CHAR_ARRAY_LENGTH_FOUR] = { - static_cast((charArrayThree[BASE64_ENCODE_INDEX0] & BASE64_ENCODE_MASK1) >> BASE64_ENCODE_OFFSET2), - static_cast(((charArrayThree[BASE64_ENCODE_INDEX0] & BASE64_ENCODE_MASK2) << BASE64_ENCODE_OFFSET4) + - ((charArrayThree[BASE64_ENCODE_INDEX1] & BASE64_ENCODE_MASK5) >> BASE64_ENCODE_OFFSET4)), - static_cast(((charArrayThree[BASE64_ENCODE_INDEX1] & BASE64_ENCODE_MASK3) << BASE64_ENCODE_OFFSET2) + - ((charArrayThree[BASE64_ENCODE_INDEX2] & BASE64_ENCODE_MASK6) >> BASE64_ENCODE_OFFSET6)), - static_cast(charArrayThree[BASE64_ENCODE_INDEX2] & BASE64_ENCODE_MASK4), - }; - for (size_t index = 0; index < CHAR_ARRAY_LENGTH_FOUR; ++index) { - charArrayFour[index] = table[index]; - } -} - -static inline void MakeCharTree(const std::array &charArrayFour, - std::array &charArrayThree) -{ - uint8_t table[CHAR_ARRAY_LENGTH_THREE] = { - static_cast((charArrayFour[BASE64_DECODE_INDEX0] << BASE64_DECODE_OFFSET2) + - ((charArrayFour[BASE64_DECODE_INDEX1] & BASE64_DECODE_MASK1) >> BASE64_DECODE_OFFSET4)), - static_cast(((charArrayFour[BASE64_DECODE_INDEX1] & BASE64_DECODE_MASK2) << BASE64_DECODE_OFFSET4) + - ((charArrayFour[BASE64_DECODE_INDEX2] & BASE64_DECODE_MASK3) >> BASE64_DECODE_OFFSET2)), - static_cast(((charArrayFour[BASE64_DECODE_INDEX2] & BASE64_DECODE_MASK4) << BASE64_DECODE_OFFSET6) + - charArrayFour[BASE64_DECODE_INDEX3]), - }; - for (size_t index = 0; index < CHAR_ARRAY_LENGTH_THREE; ++index) { - charArrayThree[index] = table[index]; - } -} - -std::string Encode(const std::string &source) -{ - auto it = source.begin(); - std::string ret; - size_t index = 0; - std::array charArrayThree = {0}; - std::array charArrayFour = {0}; - - while (it != source.end()) { - charArrayThree[index] = *it; - ++index; - ++it; - if (index != CHAR_ARRAY_LENGTH_THREE) { - continue; - } - MakeCharFour(charArrayThree, charArrayFour); - for (auto idx : charArrayFour) { - ret += BASE64_CHARS[idx]; - } - index = 0; - } - if (index == 0) { - return ret; - } - - for (auto i = index; i < CHAR_ARRAY_LENGTH_THREE; ++i) { - charArrayThree[i] = 0; - } - MakeCharFour(charArrayThree, charArrayFour); - - for (size_t i = 0; i < index + 1; ++i) { - ret += BASE64_CHARS[charArrayFour[i]]; - } - - while (index < CHAR_ARRAY_LENGTH_THREE) { - ret += '='; - ++index; - } - return ret; -} - -std::string Decode(const std::string &encoded) -{ - auto it = encoded.begin(); - size_t index = 0; - std::array charArrayThree = {0}; - std::array charArrayFour = {0}; - std::string ret; - - while (it != encoded.end() && IsBase64Char(*it)) { - charArrayFour[index] = *it; - ++index; - ++it; - if (index != CHAR_ARRAY_LENGTH_FOUR) { - continue; - } - for (index = 0; index < CHAR_ARRAY_LENGTH_FOUR; ++index) { - charArrayFour[index] = BASE64_CHARS.find(static_cast(charArrayFour[index])); - } - MakeCharTree(charArrayFour, charArrayThree); - for (auto idx : charArrayThree) { - ret += static_cast(idx); - } - index = 0; - } - if (index == 0) { - return ret; - } - - for (auto i = index; i < CHAR_ARRAY_LENGTH_FOUR; ++i) { - charArrayFour[i] = 0; - } - for (unsigned char &i : charArrayFour) { - i = BASE64_CHARS.find(static_cast(i)); - } - MakeCharTree(charArrayFour, charArrayThree); - - for (size_t i = 0; i < index - 1; i++) { - ret += static_cast(charArrayThree[i]); - } - return ret; -} -} // namespace OHOS::NetManagerStandard::Base64 \ No newline at end of file -- Gitee From 84acad3fa0b99ed92ab17c537f782b54c837139c Mon Sep 17 00:00:00 2001 From: BianYafei Date: Tue, 7 Feb 2023 13:24:09 +0800 Subject: [PATCH 7/9] ohos-sdk build failed fix Signed-off-by: BianYafei Change-Id: Ic6f0e4d1395e96c2d7b7a2557a7f0f693db13dea --- frameworks/js/napi/http/BUILD.gn | 1 + netstack_config.gni | 1 + 2 files changed, 2 insertions(+) diff --git a/frameworks/js/napi/http/BUILD.gn b/frameworks/js/napi/http/BUILD.gn index 8005893d3..048523355 100644 --- a/frameworks/js/napi/http/BUILD.gn +++ b/frameworks/js/napi/http/BUILD.gn @@ -73,6 +73,7 @@ ohos_shared_library("http") { deps += [ "$ARKUI_ROOT/napi:ace_napi", "$NETSTACK_DIR/utils/napi_utils:napi_utils_static", + "$STARTUP_ROOT/init:libbegetutil", "$THIRD_PARTY_ROOT/bounds_checking_function:libsec_static", "$THIRD_PARTY_ROOT/jsoncpp:jsoncpp_static", ] diff --git a/netstack_config.gni b/netstack_config.gni index a9468778e..0326c0070 100644 --- a/netstack_config.gni +++ b/netstack_config.gni @@ -22,3 +22,4 @@ ARKUI_ROOT = "//foundation/arkui" THIRD_PARTY_ROOT = "//third_party" HILOG_ROOT = "//base/hiviewdfx/hilog" HILOG_LITE_ROOT = "//base/hiviewdfx/hilog_lite" +STARTUP_ROOT = "//base/startup" -- Gitee From 8be1a7dd5912955edfedf8d2decea4f346411784 Mon Sep 17 00:00:00 2001 From: BianYafei Date: Tue, 7 Feb 2023 13:48:08 +0800 Subject: [PATCH 8/9] --no-edit Signed-off-by: BianYafei Change-Id: I3fe6f56281555c529b9d4a69c7eb1b7aab2bd3a4 --- frameworks/js/napi/http/BUILD.gn | 2 +- netstack_config.gni | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/http/BUILD.gn b/frameworks/js/napi/http/BUILD.gn index 048523355..5e08af10f 100644 --- a/frameworks/js/napi/http/BUILD.gn +++ b/frameworks/js/napi/http/BUILD.gn @@ -72,8 +72,8 @@ ohos_shared_library("http") { [ "$NETSTACK_DIR/utils/common_utils/src/netstack_common_utils.cpp" ] deps += [ "$ARKUI_ROOT/napi:ace_napi", + "$INIT_ROOT/interfaces/innerkits:libbegetutil", "$NETSTACK_DIR/utils/napi_utils:napi_utils_static", - "$STARTUP_ROOT/init:libbegetutil", "$THIRD_PARTY_ROOT/bounds_checking_function:libsec_static", "$THIRD_PARTY_ROOT/jsoncpp:jsoncpp_static", ] diff --git a/netstack_config.gni b/netstack_config.gni index 0326c0070..60aced6aa 100644 --- a/netstack_config.gni +++ b/netstack_config.gni @@ -22,4 +22,4 @@ ARKUI_ROOT = "//foundation/arkui" THIRD_PARTY_ROOT = "//third_party" HILOG_ROOT = "//base/hiviewdfx/hilog" HILOG_LITE_ROOT = "//base/hiviewdfx/hilog_lite" -STARTUP_ROOT = "//base/startup" +INIT_ROOT = "//base/startup/init" -- Gitee From 539cdb1e54e5a5f15d22d0be845fe7c72c541ce2 Mon Sep 17 00:00:00 2001 From: BianYafei Date: Tue, 7 Feb 2023 14:05:56 +0800 Subject: [PATCH 9/9] ohos-sdk build failed fix Signed-off-by: BianYafei Change-Id: I8fa11a335a7b5d3861002cabc95ae62246a5a91c --- frameworks/js/napi/http/BUILD.gn | 1 - frameworks/js/napi/http/http_exec/src/http_exec.cpp | 8 ++++++++ netstack_config.gni | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/http/BUILD.gn b/frameworks/js/napi/http/BUILD.gn index 5e08af10f..8005893d3 100644 --- a/frameworks/js/napi/http/BUILD.gn +++ b/frameworks/js/napi/http/BUILD.gn @@ -72,7 +72,6 @@ ohos_shared_library("http") { [ "$NETSTACK_DIR/utils/common_utils/src/netstack_common_utils.cpp" ] deps += [ "$ARKUI_ROOT/napi:ace_napi", - "$INIT_ROOT/interfaces/innerkits:libbegetutil", "$NETSTACK_DIR/utils/napi_utils:napi_utils_static", "$THIRD_PARTY_ROOT/bounds_checking_function:libsec_static", "$THIRD_PARTY_ROOT/jsoncpp:jsoncpp_static", 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 eb615fcc4..bb53faf4b 100644 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -19,7 +19,11 @@ #include #include +#ifndef WINDOWS_PLATFORM +#ifndef MAC_PLATFORM #include "parameter.h" +#endif +#endif #include "base64_utils.h" #include "cache_proxy.h" @@ -359,6 +363,8 @@ void HttpExec::ReadRespond() void HttpExec::GetGlobalHttpProxyInfo(std::string &host, int32_t &port, std::string &exclusions) { +#ifndef WINDOWS_PLATFORM +#ifndef MAC_PLATFORM char httpProxyHost[SYSPARA_MAX_SIZE] = {0}; char httpProxyPort[SYSPARA_MAX_SIZE] = {0}; char httpProxyExclusions[SYSPARA_MAX_SIZE] = {0}; @@ -378,6 +384,8 @@ void HttpExec::GetGlobalHttpProxyInfo(std::string &host, int32_t &port, std::str } port = std::atoi(httpProxyPort); +#endif +#endif } bool HttpExec::Initialize() diff --git a/netstack_config.gni b/netstack_config.gni index 60aced6aa..a9468778e 100644 --- a/netstack_config.gni +++ b/netstack_config.gni @@ -22,4 +22,3 @@ ARKUI_ROOT = "//foundation/arkui" THIRD_PARTY_ROOT = "//third_party" HILOG_ROOT = "//base/hiviewdfx/hilog" HILOG_LITE_ROOT = "//base/hiviewdfx/hilog_lite" -INIT_ROOT = "//base/startup/init" -- Gitee