OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/base/host_mapping_rules.h" | 5 #include "net/base/host_mapping_rules.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/pattern.h" | 8 #include "base/strings/pattern.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 std::string replacement_hostname; | 21 std::string replacement_hostname; |
22 int replacement_port; | 22 int replacement_port; |
23 }; | 23 }; |
24 | 24 |
25 struct HostMappingRules::ExclusionRule { | 25 struct HostMappingRules::ExclusionRule { |
26 std::string hostname_pattern; | 26 std::string hostname_pattern; |
27 }; | 27 }; |
28 | 28 |
29 HostMappingRules::HostMappingRules() {} | 29 HostMappingRules::HostMappingRules() {} |
30 | 30 |
31 HostMappingRules::HostMappingRules(const HostMappingRules& host_mapping_rules) = | |
32 default; | |
33 | |
31 HostMappingRules::~HostMappingRules() {} | 34 HostMappingRules::~HostMappingRules() {} |
32 | 35 |
36 HostMappingRules& HostMappingRules::operator=( | |
37 const HostMappingRules& host_mapping_rules) = default; | |
38 | |
33 bool HostMappingRules::RewriteHost(HostPortPair* host_port) const { | 39 bool HostMappingRules::RewriteHost(HostPortPair* host_port) const { |
34 // Check if the hostname was excluded. | |
35 for (ExclusionRuleList::const_iterator it = exclusion_rules_.begin(); | |
36 it != exclusion_rules_.end(); ++it) { | |
37 const ExclusionRule& rule = *it; | |
38 if (base::MatchPattern(host_port->host(), rule.hostname_pattern)) | |
39 return false; | |
40 } | |
41 | |
Randy Smith (Not in Mondays)
2017/05/25 17:50:48
The movement of the exclusion check looks like a b
mmenke
2017/05/25 18:07:10
I don't think this is a behavior change. This was
Randy Smith (Not in Mondays)
2017/05/25 18:17:06
I'm sorry, I was reading too fast, and read this a
| |
42 // Check if the hostname was remapped. | 40 // Check if the hostname was remapped. |
43 for (MapRuleList::const_iterator it = map_rules_.begin(); | 41 for (const auto& rule : map_rules_) { |
44 it != map_rules_.end(); ++it) { | |
45 const MapRule& rule = *it; | |
46 | |
47 // The rule's hostname_pattern will be something like: | 42 // The rule's hostname_pattern will be something like: |
48 // www.foo.com | 43 // www.foo.com |
49 // *.foo.com | 44 // *.foo.com |
50 // www.foo.com:1234 | 45 // www.foo.com:1234 |
51 // *.foo.com:1234 | 46 // *.foo.com:1234 |
52 // First, we'll check for a match just on hostname. | 47 // First, we'll check for a match just on hostname. |
53 // If that fails, we'll check for a match with both hostname and port. | 48 // If that fails, we'll check for a match with both hostname and port. |
54 if (!base::MatchPattern(host_port->host(), rule.hostname_pattern)) { | 49 if (!base::MatchPattern(host_port->host(), rule.hostname_pattern)) { |
55 std::string host_port_string = host_port->ToString(); | 50 std::string host_port_string = host_port->ToString(); |
56 if (!base::MatchPattern(host_port_string, rule.hostname_pattern)) | 51 if (!base::MatchPattern(host_port_string, rule.hostname_pattern)) |
57 continue; // This rule doesn't apply. | 52 continue; // This rule doesn't apply. |
58 } | 53 } |
59 | 54 |
55 // Check if the hostname was excluded. | |
56 for (const auto& rule : exclusion_rules_) { | |
57 if (base::MatchPattern(host_port->host(), rule.hostname_pattern)) | |
58 return false; | |
59 } | |
60 | |
60 host_port->set_host(rule.replacement_hostname); | 61 host_port->set_host(rule.replacement_hostname); |
61 if (rule.replacement_port != -1) | 62 if (rule.replacement_port != -1) |
62 host_port->set_port(static_cast<uint16_t>(rule.replacement_port)); | 63 host_port->set_port(static_cast<uint16_t>(rule.replacement_port)); |
63 return true; | 64 return true; |
64 } | 65 } |
65 | 66 |
66 return false; | 67 return false; |
67 } | 68 } |
68 | 69 |
69 bool HostMappingRules::AddRuleFromString(const std::string& rule_string) { | 70 bool HostMappingRules::AddRuleFromString(const std::string& rule_string) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 map_rules_.clear(); | 102 map_rules_.clear(); |
102 | 103 |
103 base::StringTokenizer rules(rules_string, ","); | 104 base::StringTokenizer rules(rules_string, ","); |
104 while (rules.GetNext()) { | 105 while (rules.GetNext()) { |
105 bool ok = AddRuleFromString(rules.token()); | 106 bool ok = AddRuleFromString(rules.token()); |
106 LOG_IF(ERROR, !ok) << "Failed parsing rule: " << rules.token(); | 107 LOG_IF(ERROR, !ok) << "Failed parsing rule: " << rules.token(); |
107 } | 108 } |
108 } | 109 } |
109 | 110 |
110 } // namespace net | 111 } // namespace net |
OLD | NEW |