Commit 1064f4cd authored by Shimi Zhang's avatar Shimi Zhang Committed by Commit Bot

[ProxyBypassRules] Extract ProxyBypassRules::Rule out

We are going to expose the internal Rule class and some common rules
sub-classes inside of ProxyBypassRules, so we could build different
rule set based on different business logic.

Bug: 1030092
Change-Id: I054e05bf1302506bee77e5c1a8e30ee8f973daea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2008012
Commit-Queue: Shimi Zhang <ctzsm@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736558}
parent ac4f3fc1
...@@ -478,6 +478,9 @@ component("net") { ...@@ -478,6 +478,9 @@ component("net") {
"base/proxy_server.h", "base/proxy_server.h",
"base/request_priority.cc", "base/request_priority.cc",
"base/request_priority.h", "base/request_priority.h",
"base/scheme_host_port_matcher_result.h",
"base/scheme_host_port_matcher_rule.cc",
"base/scheme_host_port_matcher_rule.h",
"base/static_cookie_policy.cc", "base/static_cookie_policy.cc",
"base/static_cookie_policy.h", "base/static_cookie_policy.h",
"base/test_data_stream.cc", "base/test_data_stream.cc",
...@@ -4129,6 +4132,7 @@ test("net_unittests") { ...@@ -4129,6 +4132,7 @@ test("net_unittests") {
"base/prioritized_task_runner_unittest.cc", "base/prioritized_task_runner_unittest.cc",
"base/priority_queue_unittest.cc", "base/priority_queue_unittest.cc",
"base/registry_controlled_domains/registry_controlled_domain_unittest.cc", "base/registry_controlled_domains/registry_controlled_domain_unittest.cc",
"base/scheme_host_port_matcher_rule_unittest.cc",
"base/static_cookie_policy_unittest.cc", "base/static_cookie_policy_unittest.cc",
"base/test_completion_callback_unittest.cc", "base/test_completion_callback_unittest.cc",
"base/test_proxy_delegate.cc", "base/test_proxy_delegate.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_BASE_SCHEME_HOST_PORT_MATCHER_RESULT_H_
#define NET_BASE_SCHEME_HOST_PORT_MATCHER_RESULT_H_
namespace net {
// The result of evaluating an URLMatcherRule.
//
// Matches can be for including a URL, or for excluding a URL, or neither of
// them.
enum class SchemeHostPortMatcherResult {
// No match.
kNoMatch,
// The URL should be included.
kInclude,
// The URL should be excluded.
kExclude,
};
} // namespace net
#endif // NET_BASE_SCHEME_HOST_PORT_MATCHER_RESULT_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/base/scheme_host_port_matcher_rule.h"
#include "base/strings/pattern.h"
#include "base/strings/stringprintf.h"
#include "url/url_util.h"
namespace net {
namespace {
std::string AddBracketsIfIPv6(const IPAddress& ip_address) {
std::string ip_host = ip_address.ToString();
if (ip_address.IsIPv6())
return base::StringPrintf("[%s]", ip_host.c_str());
return ip_host;
}
} // namespace
SchemeHostPortMatcherHostnamePatternRule::
SchemeHostPortMatcherHostnamePatternRule(
const std::string& optional_scheme,
const std::string& hostname_pattern,
int optional_port)
: optional_scheme_(base::ToLowerASCII(optional_scheme)),
hostname_pattern_(base::ToLowerASCII(hostname_pattern)),
optional_port_(optional_port) {
// |hostname_pattern| shouldn't be an IP address.
DCHECK(!url::HostIsIPAddress(hostname_pattern));
}
SchemeHostPortMatcherResult SchemeHostPortMatcherHostnamePatternRule::Evaluate(
const GURL& url) const {
if (optional_port_ != -1 && url.EffectiveIntPort() != optional_port_) {
// Didn't match port expectation.
return SchemeHostPortMatcherResult::kNoMatch;
}
if (!optional_scheme_.empty() && url.scheme() != optional_scheme_) {
// Didn't match scheme expectation.
return SchemeHostPortMatcherResult::kNoMatch;
}
// Note it is necessary to lower-case the host, since GURL uses capital
// letters for percent-escaped characters.
return base::MatchPattern(url.host(), hostname_pattern_)
? SchemeHostPortMatcherResult::kInclude
: SchemeHostPortMatcherResult::kNoMatch;
}
std::string SchemeHostPortMatcherHostnamePatternRule::ToString() const {
std::string str;
if (!optional_scheme_.empty())
base::StringAppendF(&str, "%s://", optional_scheme_.c_str());
str += hostname_pattern_;
if (optional_port_ != -1)
base::StringAppendF(&str, ":%d", optional_port_);
return str;
}
SchemeHostPortMatcherIPHostRule::SchemeHostPortMatcherIPHostRule(
const std::string& optional_scheme,
const IPEndPoint& ip_end_point)
: optional_scheme_(base::ToLowerASCII(optional_scheme)),
ip_host_(AddBracketsIfIPv6(ip_end_point.address())),
optional_port_(ip_end_point.port()) {}
SchemeHostPortMatcherResult SchemeHostPortMatcherIPHostRule::Evaluate(
const GURL& url) const {
if (optional_port_ != 0 && url.EffectiveIntPort() != optional_port_) {
// Didn't match port expectation.
return SchemeHostPortMatcherResult::kNoMatch;
}
if (!optional_scheme_.empty() && url.scheme() != optional_scheme_) {
// Didn't match scheme expectation.
return SchemeHostPortMatcherResult::kNoMatch;
}
// Note it is necessary to lower-case the host, since GURL uses capital
// letters for percent-escaped characters.
return base::MatchPattern(url.host(), ip_host_)
? SchemeHostPortMatcherResult::kInclude
: SchemeHostPortMatcherResult::kNoMatch;
}
std::string SchemeHostPortMatcherIPHostRule::ToString() const {
std::string str;
if (!optional_scheme_.empty())
base::StringAppendF(&str, "%s://", optional_scheme_.c_str());
str += ip_host_;
if (optional_port_ != 0)
base::StringAppendF(&str, ":%d", optional_port_);
return str;
}
SchemeHostPortMatcherIPBlockRule::SchemeHostPortMatcherIPBlockRule(
const std::string& description,
const std::string& optional_scheme,
const IPAddress& ip_prefix,
size_t prefix_length_in_bits)
: description_(description),
optional_scheme_(optional_scheme),
ip_prefix_(ip_prefix),
prefix_length_in_bits_(prefix_length_in_bits) {}
SchemeHostPortMatcherResult SchemeHostPortMatcherIPBlockRule::Evaluate(
const GURL& url) const {
if (!url.HostIsIPAddress())
return SchemeHostPortMatcherResult::kNoMatch;
if (!optional_scheme_.empty() && url.scheme() != optional_scheme_) {
// Didn't match scheme expectation.
return SchemeHostPortMatcherResult::kNoMatch;
}
// Parse the input IP literal to a number.
IPAddress ip_address;
if (!ip_address.AssignFromIPLiteral(url.HostNoBracketsPiece()))
return SchemeHostPortMatcherResult::kNoMatch;
// Test if it has the expected prefix.
return IPAddressMatchesPrefix(ip_address, ip_prefix_, prefix_length_in_bits_)
? SchemeHostPortMatcherResult::kInclude
: SchemeHostPortMatcherResult::kNoMatch;
}
std::string SchemeHostPortMatcherIPBlockRule::ToString() const {
return description_;
}
} // namespace net
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_BASE_SCHEME_HOST_PORT_MATCHER_RULE_H_
#define NET_BASE_SCHEME_HOST_PORT_MATCHER_RULE_H_
#include <string>
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_export.h"
#include "net/base/scheme_host_port_matcher_result.h"
#include "url/gurl.h"
namespace net {
// Interface for an individual SchemeHostPortMatcher rule.
class NET_EXPORT SchemeHostPortMatcherRule {
public:
SchemeHostPortMatcherRule() = default;
SchemeHostPortMatcherRule(const SchemeHostPortMatcherRule&) = delete;
SchemeHostPortMatcherRule& operator=(const SchemeHostPortMatcherRule&) =
delete;
virtual ~SchemeHostPortMatcherRule() = default;
// Evaluates the rule against |url|.
virtual SchemeHostPortMatcherResult Evaluate(const GURL& url) const = 0;
// Returns a string representation of this rule. The returned string will not
// match any distinguishable rule of any type.
virtual std::string ToString() const = 0;
};
// Rule that matches URLs with wildcard hostname patterns, and
// scheme/port restrictions.
//
// For example:
// *.google.com
// https://*.google.com
// google.com:443
class NET_EXPORT SchemeHostPortMatcherHostnamePatternRule
: public SchemeHostPortMatcherRule {
public:
SchemeHostPortMatcherHostnamePatternRule(const std::string& optional_scheme,
const std::string& hostname_pattern,
int optional_port);
SchemeHostPortMatcherHostnamePatternRule(
const SchemeHostPortMatcherHostnamePatternRule&) = delete;
SchemeHostPortMatcherHostnamePatternRule& operator=(
const SchemeHostPortMatcherHostnamePatternRule&) = delete;
// SchemeHostPortMatcherRule implementation:
SchemeHostPortMatcherResult Evaluate(const GURL& url) const override;
std::string ToString() const override;
private:
const std::string optional_scheme_;
const std::string hostname_pattern_;
const int optional_port_;
};
// Rule that matches URLs with IP address as hostname, and scheme/port
// restrictions. * only works in the host portion. i18n domain names must be
// input in punycode format.
//
// For example:
// 127.0.0.1,
// http://127.0.0.1
// [::1]
// [0:0::1]
// http://[::1]:99
class NET_EXPORT SchemeHostPortMatcherIPHostRule
: public SchemeHostPortMatcherRule {
public:
SchemeHostPortMatcherIPHostRule(const std::string& optional_scheme,
const IPEndPoint& ip_end_point);
SchemeHostPortMatcherIPHostRule(const SchemeHostPortMatcherIPHostRule&) =
delete;
SchemeHostPortMatcherIPHostRule& operator=(
const SchemeHostPortMatcherIPHostRule&) = delete;
// SchemeHostPortMatcherRule implementation:
SchemeHostPortMatcherResult Evaluate(const GURL& url) const override;
std::string ToString() const override;
private:
const std::string optional_scheme_;
const std::string ip_host_;
const int optional_port_;
};
// Rule for matching a URL that is an IP address, if that IP address falls
// within a certain numeric range.
//
// For example:
// 127.0.0.1/8.
// FE80::/10
// but not http://127.0.0.1:7/8 or http://[FE80::]/10 (IPv6 with brackets).
class NET_EXPORT SchemeHostPortMatcherIPBlockRule
: public SchemeHostPortMatcherRule {
public:
// |ip_prefix| + |prefix_length| define the IP block to match.
SchemeHostPortMatcherIPBlockRule(const std::string& description,
const std::string& optional_scheme,
const IPAddress& ip_prefix,
size_t prefix_length_in_bits);
SchemeHostPortMatcherIPBlockRule(const SchemeHostPortMatcherIPBlockRule&) =
delete;
SchemeHostPortMatcherIPBlockRule& operator=(
const SchemeHostPortMatcherIPBlockRule&) = delete;
// SchemeHostPortMatcherRule implementation:
SchemeHostPortMatcherResult Evaluate(const GURL& url) const override;
std::string ToString() const override;
private:
const std::string description_;
const std::string optional_scheme_;
const IPAddress ip_prefix_;
const size_t prefix_length_in_bits_;
};
} // namespace net
#endif // NET_BASE_SCHEME_HOST_PORT_MATCHER_RULE_H_
This diff is collapsed.
...@@ -73,55 +73,15 @@ bool IsIPv4MappedLoopback(const GURL& url) { ...@@ -73,55 +73,15 @@ bool IsIPv4MappedLoopback(const GURL& url) {
return ip_address.bytes()[12] == 127; return ip_address.bytes()[12] == 127;
} }
class HostnamePatternRule : public ProxyBypassRules::Rule { class BypassSimpleHostnamesRule : public SchemeHostPortMatcherRule {
public:
HostnamePatternRule(const std::string& optional_scheme,
const std::string& hostname_pattern,
int optional_port)
: optional_scheme_(base::ToLowerASCII(optional_scheme)),
hostname_pattern_(base::ToLowerASCII(hostname_pattern)),
optional_port_(optional_port) {}
Result Evaluate(const GURL& url) const override {
if (optional_port_ != -1 && url.EffectiveIntPort() != optional_port_)
return Result::kNoMatch; // Didn't match port expectation.
if (!optional_scheme_.empty() && url.scheme() != optional_scheme_)
return Result::kNoMatch; // Didn't match scheme expectation.
// Note it is necessary to lower-case the host, since GURL uses capital
// letters for percent-escaped characters.
return base::MatchPattern(url.host(), hostname_pattern_) ? Result::kBypass
: Result::kNoMatch;
}
std::string ToString() const override {
std::string str;
if (!optional_scheme_.empty())
base::StringAppendF(&str, "%s://", optional_scheme_.c_str());
str += hostname_pattern_;
if (optional_port_ != -1)
base::StringAppendF(&str, ":%d", optional_port_);
return str;
}
private:
const std::string optional_scheme_;
const std::string hostname_pattern_;
const int optional_port_;
DISALLOW_COPY_AND_ASSIGN(HostnamePatternRule);
};
class BypassSimpleHostnamesRule : public ProxyBypassRules::Rule {
public: public:
BypassSimpleHostnamesRule() = default; BypassSimpleHostnamesRule() = default;
Result Evaluate(const GURL& url) const override { SchemeHostPortMatcherResult Evaluate(const GURL& url) const override {
return ((url.host_piece().find('.') == std::string::npos) && return ((url.host_piece().find('.') == std::string::npos) &&
!url.HostIsIPAddress()) !url.HostIsIPAddress())
? Result::kBypass ? SchemeHostPortMatcherResult::kInclude
: Result::kNoMatch; : SchemeHostPortMatcherResult::kNoMatch;
} }
std::string ToString() const override { return kBypassSimpleHostnames; } std::string ToString() const override { return kBypassSimpleHostnames; }
...@@ -130,13 +90,14 @@ class BypassSimpleHostnamesRule : public ProxyBypassRules::Rule { ...@@ -130,13 +90,14 @@ class BypassSimpleHostnamesRule : public ProxyBypassRules::Rule {
DISALLOW_COPY_AND_ASSIGN(BypassSimpleHostnamesRule); DISALLOW_COPY_AND_ASSIGN(BypassSimpleHostnamesRule);
}; };
class SubtractImplicitBypassesRule : public ProxyBypassRules::Rule { class SubtractImplicitBypassesRule : public SchemeHostPortMatcherRule {
public: public:
SubtractImplicitBypassesRule() = default; SubtractImplicitBypassesRule() = default;
Result Evaluate(const GURL& url) const override { SchemeHostPortMatcherResult Evaluate(const GURL& url) const override {
return ProxyBypassRules::MatchesImplicitRules(url) ? Result::kDontBypass return ProxyBypassRules::MatchesImplicitRules(url)
: Result::kNoMatch; ? SchemeHostPortMatcherResult::kExclude
: SchemeHostPortMatcherResult::kNoMatch;
} }
std::string ToString() const override { return kSubtractImplicitBypasses; } std::string ToString() const override { return kSubtractImplicitBypasses; }
...@@ -145,52 +106,7 @@ class SubtractImplicitBypassesRule : public ProxyBypassRules::Rule { ...@@ -145,52 +106,7 @@ class SubtractImplicitBypassesRule : public ProxyBypassRules::Rule {
DISALLOW_COPY_AND_ASSIGN(SubtractImplicitBypassesRule); DISALLOW_COPY_AND_ASSIGN(SubtractImplicitBypassesRule);
}; };
// Rule for matching a URL that is an IP address, if that IP address falls std::unique_ptr<SchemeHostPortMatcherRule> ParseRule(
// within a certain numeric range. For example, you could use this rule to
// match all the IPs in the CIDR block 10.10.3.4/24.
class IPBlockRule : public ProxyBypassRules::Rule {
public:
// |ip_prefix| + |prefix_length| define the IP block to match.
IPBlockRule(const std::string& description,
const std::string& optional_scheme,
const IPAddress& ip_prefix,
size_t prefix_length_in_bits)
: description_(description),
optional_scheme_(optional_scheme),
ip_prefix_(ip_prefix),
prefix_length_in_bits_(prefix_length_in_bits) {}
Result Evaluate(const GURL& url) const override {
if (!url.HostIsIPAddress())
return Result::kNoMatch;
if (!optional_scheme_.empty() && url.scheme() != optional_scheme_)
return Result::kNoMatch; // Didn't match scheme expectation.
// Parse the input IP literal to a number.
IPAddress ip_address;
if (!ip_address.AssignFromIPLiteral(url.HostNoBracketsPiece()))
return Result::kNoMatch;
// Test if it has the expected prefix.
return IPAddressMatchesPrefix(ip_address, ip_prefix_,
prefix_length_in_bits_)
? Result::kBypass
: Result::kNoMatch;
}
std::string ToString() const override { return description_; }
private:
const std::string description_;
const std::string optional_scheme_;
const IPAddress ip_prefix_;
const size_t prefix_length_in_bits_;
DISALLOW_COPY_AND_ASSIGN(IPBlockRule);
};
std::unique_ptr<ProxyBypassRules::Rule> ParseRule(
const std::string& raw_untrimmed, const std::string& raw_untrimmed,
ProxyBypassRules::ParseFormat format) { ProxyBypassRules::ParseFormat format) {
std::string raw; std::string raw;
...@@ -225,8 +141,8 @@ std::unique_ptr<ProxyBypassRules::Rule> ParseRule( ...@@ -225,8 +141,8 @@ std::unique_ptr<ProxyBypassRules::Rule> ParseRule(
if (!ParseCIDRBlock(raw, &ip_prefix, &prefix_length_in_bits)) if (!ParseCIDRBlock(raw, &ip_prefix, &prefix_length_in_bits))
return nullptr; return nullptr;
return std::make_unique<IPBlockRule>(raw, scheme, ip_prefix, return std::make_unique<SchemeHostPortMatcherIPBlockRule>(
prefix_length_in_bits); raw, scheme, ip_prefix, prefix_length_in_bits);
} }
// Check if we have an <ip-address>[:port] input. We need to treat this // Check if we have an <ip-address>[:port] input. We need to treat this
...@@ -239,14 +155,12 @@ std::unique_ptr<ProxyBypassRules::Rule> ParseRule( ...@@ -239,14 +155,12 @@ std::unique_ptr<ProxyBypassRules::Rule> ParseRule(
if (host.find('\0') != std::string::npos) if (host.find('\0') != std::string::npos)
return nullptr; return nullptr;
// Note that HostPortPair is used to merely to convert any IPv6 literals to IPAddress ip_address;
// a URL-safe format that can be used by canonicalization below. if (ip_address.AssignFromIPLiteral(host)) {
std::string bracketed_host = HostPortPair(host, 80).HostForURL(); // Instead of -1, 0 is invalid for IPEndPoint.
if (url::HostIsIPAddress(bracketed_host)) { int adjusted_port = port == -1 ? 0 : port;
// Canonicalize the IP literal before adding it as a string pattern. return std::make_unique<SchemeHostPortMatcherIPHostRule>(
GURL tmp_url("http://" + bracketed_host); scheme, IPEndPoint(ip_address, adjusted_port));
return std::make_unique<HostnamePatternRule>(scheme, tmp_url.host(),
port);
} }
} }
...@@ -273,21 +187,14 @@ std::unique_ptr<ProxyBypassRules::Rule> ParseRule( ...@@ -273,21 +187,14 @@ std::unique_ptr<ProxyBypassRules::Rule> ParseRule(
!base::StartsWith(raw, "*", base::CompareCase::SENSITIVE)) !base::StartsWith(raw, "*", base::CompareCase::SENSITIVE))
raw = "*" + raw; raw = "*" + raw;
return std::make_unique<HostnamePatternRule>(scheme, raw, port); return std::make_unique<SchemeHostPortMatcherHostnamePatternRule>(scheme, raw,
port);
} }
} // namespace } // namespace
constexpr char net::ProxyBypassRules::kBypassListDelimeter[]; constexpr char net::ProxyBypassRules::kBypassListDelimeter[];
ProxyBypassRules::Rule::Rule() = default;
ProxyBypassRules::Rule::~Rule() = default;
bool ProxyBypassRules::Rule::Equals(const Rule& rule) const {
return ToString() == rule.ToString();
}
ProxyBypassRules::ProxyBypassRules() = default; ProxyBypassRules::ProxyBypassRules() = default;
ProxyBypassRules::ProxyBypassRules(const ProxyBypassRules& rhs) { ProxyBypassRules::ProxyBypassRules(const ProxyBypassRules& rhs) {
...@@ -316,7 +223,7 @@ bool ProxyBypassRules::Matches(const GURL& url, bool reverse) const { ...@@ -316,7 +223,7 @@ bool ProxyBypassRules::Matches(const GURL& url, bool reverse) const {
// found. If no matches are found then the implicit rules are consulted. // found. If no matches are found then the implicit rules are consulted.
// //
// The order of evaluation generally doesn't matter, since the common // The order of evaluation generally doesn't matter, since the common
// case is to have a set of (positive) bypass rules. // case is to have a set of (positive) bypass rules.,
// //
// However when mixing positive and negative bypass rules evaluation // However when mixing positive and negative bypass rules evaluation
// order makes a difference. The chosen evaluation order here matches // order makes a difference. The chosen evaluation order here matches
...@@ -331,14 +238,14 @@ bool ProxyBypassRules::Matches(const GURL& url, bool reverse) const { ...@@ -331,14 +238,14 @@ bool ProxyBypassRules::Matches(const GURL& url, bool reverse) const {
// expected to return true for (b), since the final rule "localhost" // expected to return true for (b), since the final rule "localhost"
// bypasses it again. // bypasses it again.
for (auto it = rules_.rbegin(); it != rules_.rend(); ++it) { for (auto it = rules_.rbegin(); it != rules_.rend(); ++it) {
const std::unique_ptr<Rule>& rule = *it; const std::unique_ptr<SchemeHostPortMatcherRule>& rule = *it;
switch (rule->Evaluate(url)) { switch (rule->Evaluate(url)) {
case Rule::Result::kBypass: case SchemeHostPortMatcherResult::kInclude:
return !reverse; return !reverse;
case Rule::Result::kDontBypass: case SchemeHostPortMatcherResult::kExclude:
return reverse; return reverse;
case Rule::Result::kNoMatch: case SchemeHostPortMatcherResult::kNoMatch:
continue; continue;
} }
} }
...@@ -356,7 +263,7 @@ bool ProxyBypassRules::operator==(const ProxyBypassRules& other) const { ...@@ -356,7 +263,7 @@ bool ProxyBypassRules::operator==(const ProxyBypassRules& other) const {
return false; return false;
for (size_t i = 0; i < rules_.size(); ++i) { for (size_t i = 0; i < rules_.size(); ++i) {
if (!rules_[i]->Equals(*other.rules_[i])) if (rules_[i]->ToString() != other.rules_[i]->ToString())
return false; return false;
} }
return true; return true;
...@@ -378,7 +285,7 @@ bool ProxyBypassRules::AddRuleForHostname(const std::string& optional_scheme, ...@@ -378,7 +285,7 @@ bool ProxyBypassRules::AddRuleForHostname(const std::string& optional_scheme,
if (hostname_pattern.empty()) if (hostname_pattern.empty())
return false; return false;
rules_.push_back(std::make_unique<HostnamePatternRule>( rules_.push_back(std::make_unique<SchemeHostPortMatcherHostnamePatternRule>(
optional_scheme, hostname_pattern, optional_port)); optional_scheme, hostname_pattern, optional_port));
return true; return true;
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
#include "net/base/scheme_host_port_matcher_rule.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace net { namespace net {
...@@ -31,37 +32,6 @@ namespace net { ...@@ -31,37 +32,6 @@ namespace net {
// MatchesImplicitRules() for details. // MatchesImplicitRules() for details.
class NET_EXPORT ProxyBypassRules { class NET_EXPORT ProxyBypassRules {
public: public:
// Interface for an individual proxy bypass rule.
class NET_EXPORT Rule {
public:
// Describes the result of calling Rule::Evaluate() for a particular URL.
enum class Result {
// The URL does not match this rule.
kNoMatch,
// The URL matches this rule, and should bypass the proxy.
kBypass,
// The URL matches this rule, and should NOT bypass the proxy.
kDontBypass,
};
Rule();
virtual ~Rule();
// Evaluates the rule against |url|.
virtual Result Evaluate(const GURL& url) const = 0;
// Returns a string representation of this rule (using
// ParseFormat::kDefault).
virtual std::string ToString() const = 0;
bool Equals(const Rule& rule) const;
private:
DISALLOW_COPY_AND_ASSIGN(Rule);
};
// The input format to use when parsing proxy bypass rules. This format // The input format to use when parsing proxy bypass rules. This format
// only applies when parsing, since once parsed any serialization will be in // only applies when parsing, since once parsed any serialization will be in
// terms of ParseFormat::kDefault. // terms of ParseFormat::kDefault.
...@@ -78,7 +48,7 @@ class NET_EXPORT ProxyBypassRules { ...@@ -78,7 +48,7 @@ class NET_EXPORT ProxyBypassRules {
kHostnameSuffixMatching, kHostnameSuffixMatching,
}; };
typedef std::vector<std::unique_ptr<Rule>> RuleList; typedef std::vector<std::unique_ptr<SchemeHostPortMatcherRule>> RuleList;
// Note: This class supports copy constructor and assignment. // Note: This class supports copy constructor and assignment.
ProxyBypassRules(); ProxyBypassRules();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment