1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "proxy_config.h" 17 18 #include <string> 19 20 #include "nweb_log.h" 21 22 namespace OHOS { 23 namespace NWeb { 24 const std::string BYPASS_HOST_NAMES = "<local>"; 25 const std::string CLEAR_IMPLICIT_RULES = "<-loopback>"; 26 const std::string DIRECT = "direct://"; 27 InsertBypassRule(const std::string & bypassRule)28void ProxyConfig::InsertBypassRule(const std::string& bypassRule) 29 { 30 bypassRules_.push_back(bypassRule); 31 } 32 InsertDirectRule(int32_t proxySchemeFilter)33void ProxyConfig::InsertDirectRule(int32_t proxySchemeFilter) 34 { 35 proxyRules_.push_back(ProxyRule(DIRECT, proxySchemeFilter)); 36 } 37 InsertProxyRule(const std::string & proxyUrl,int32_t proxySchemeFilter)38void ProxyConfig::InsertProxyRule(const std::string& proxyUrl, int32_t proxySchemeFilter) 39 { 40 proxyRules_.push_back(ProxyRule(proxyUrl, proxySchemeFilter)); 41 } 42 BypassHostnamesWithoutPeriod()43void ProxyConfig::BypassHostnamesWithoutPeriod() 44 { 45 InsertBypassRule(BYPASS_HOST_NAMES.c_str()); 46 } 47 ClearImplicitRules()48void ProxyConfig::ClearImplicitRules() 49 { 50 InsertBypassRule(CLEAR_IMPLICIT_RULES.c_str()); 51 } 52 EnableReverseBypass(const bool enable)53void ProxyConfig::EnableReverseBypass(const bool enable) 54 { 55 enbaleReverseBypass_ = enable; 56 } 57 GetBypassRules()58const std::vector<std::string>& ProxyConfig::GetBypassRules() 59 { 60 return bypassRules_; 61 } 62 GetProxyRules()63const std::vector<ProxyRule>& ProxyConfig::GetProxyRules() 64 { 65 return proxyRules_; 66 } 67 IsReverseBypassEnabled()68bool ProxyConfig::IsReverseBypassEnabled() 69 { 70 return enbaleReverseBypass_; 71 } 72 } // namespace NWeb 73 } // namespace OHOS