Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: net/base/host_mapping_rules.cc

Issue 3177026: Add a feature to the HostResolverRules to be able to match rules only... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/string_tokenizer.h" 8 #include "base/string_tokenizer.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/host_port_pair.h" 10 #include "net/base/host_port_pair.h"
(...skipping 10 matching lines...) Expand all
21 const ExclusionRule& rule = *it; 21 const ExclusionRule& rule = *it;
22 if (MatchPatternASCII(host_port->host(), rule.hostname_pattern)) 22 if (MatchPatternASCII(host_port->host(), rule.hostname_pattern))
23 return false; 23 return false;
24 } 24 }
25 25
26 // Check if the hostname was remapped. 26 // Check if the hostname was remapped.
27 for (MapRuleList::const_iterator it = map_rules_.begin(); 27 for (MapRuleList::const_iterator it = map_rules_.begin();
28 it != map_rules_.end(); ++it) { 28 it != map_rules_.end(); ++it) {
29 const MapRule& rule = *it; 29 const MapRule& rule = *it;
30 30
31 if (!MatchPatternASCII(host_port->host(), rule.hostname_pattern)) 31 // The rule's hostname_pattern will be something like:
32 continue; // This rule doesn't apply. 32 // www.foo.com
33 // *.foo.com
34 // www.foo.com:1234
35 // *.foo.com:1234
36 // First, we'll check for a match just on hostname.
37 // If that fails, we'll check for a match with both hostname and port.
38 if (!MatchPatternASCII(host_port->host(), rule.hostname_pattern)) {
39 std::string host_port_string = host_port->ToString();
40 if (!MatchPatternASCII(host_port_string, rule.hostname_pattern))
41 continue; // This rule doesn't apply.
42 }
33 43
34 host_port->set_host(rule.replacement_hostname); 44 host_port->set_host(rule.replacement_hostname);
35 if (rule.replacement_port != -1) 45 if (rule.replacement_port != -1)
36 host_port->set_port(rule.replacement_port); 46 host_port->set_port(rule.replacement_port);
37 return true; 47 return true;
38 } 48 }
39 49
40 return false; 50 return false;
41 } 51 }
42 52
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 map_rules_.clear(); 86 map_rules_.clear();
77 87
78 StringTokenizer rules(rules_string, ","); 88 StringTokenizer rules(rules_string, ",");
79 while (rules.GetNext()) { 89 while (rules.GetNext()) {
80 bool ok = AddRuleFromString(rules.token()); 90 bool ok = AddRuleFromString(rules.token());
81 LOG_IF(ERROR, !ok) << "Failed parsing rule: " << rules.token(); 91 LOG_IF(ERROR, !ok) << "Failed parsing rule: " << rules.token();
82 } 92 }
83 } 93 }
84 94
85 } // namespace net 95 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/host_mapping_rules_unittest.cc » ('j') | net/base/host_mapping_rules_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698