summaryrefslogtreecommitdiffstats
path: root/net/base/host_mapping_rules.h
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-12 22:47:14 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-12 22:47:14 +0000
commitb6a50183e21e21207f2dff4953d19aa5be62d166 (patch)
tree9a937074af7bb0c5ff9c1987f68a4055bb54762c /net/base/host_mapping_rules.h
parent6402aaec3c045969b60ef7b782ce25992d07a70f (diff)
downloadchromium_src-b6a50183e21e21207f2dff4953d19aa5be62d166.zip
chromium_src-b6a50183e21e21207f2dff4953d19aa5be62d166.tar.gz
chromium_src-b6a50183e21e21207f2dff4953d19aa5be62d166.tar.bz2
Add --host-rules support.
The format for --host-rules is identical to --host-resolver-rules. The difference is that --host-rules affects the endpoint of the HttpNetworkTransaction, not just the host resolver. So, this means the host passed to the host resolver and the TCP connect(), the tunnel CONNECT, and the SOCKS connect will be different. Review URL: http://codereview.chromium.org/2057007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47083 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/host_mapping_rules.h')
-rw-r--r--net/base/host_mapping_rules.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/net/base/host_mapping_rules.h b/net/base/host_mapping_rules.h
new file mode 100644
index 0000000..a754a47
--- /dev/null
+++ b/net/base/host_mapping_rules.h
@@ -0,0 +1,61 @@
+// Copyright (c) 2010 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_HOST_MAPPING_RULES_H_
+#define NET_BASE_HOST_MAPPING_RULES_H_
+
+#include <string>
+#include <vector>
+#include "base/basictypes.h"
+
+namespace net {
+
+struct HostPortPair;
+
+class HostMappingRules {
+ public:
+ HostMappingRules();
+
+ // Modifies |*host_port| based on the current rules. Returns true if the
+ // RequestInfo was modified, false otherwise.
+ bool RewriteHost(HostPortPair* host_port) const;
+
+ // Adds a rule to this mapper. The format of the rule can be one of:
+ //
+ // "MAP" <hostname_pattern> <replacement_host> [":" <replacement_port>]
+ // "EXCLUDE" <hostname_pattern>
+ //
+ // The <replacement_host> can be either a hostname, or an IP address literal.
+ //
+ // Returns true if the rule was successfully parsed and added.
+ bool AddRuleFromString(const std::string& rule_string);
+
+ // Sets the rules from a comma separated list of rules.
+ void SetRulesFromString(const std::string& rules_string);
+
+ private:
+ struct MapRule {
+ MapRule() : replacement_port(-1) {}
+
+ std::string hostname_pattern;
+ std::string replacement_hostname;
+ int replacement_port;
+ };
+
+ struct ExclusionRule {
+ std::string hostname_pattern;
+ };
+
+ typedef std::vector<MapRule> MapRuleList;
+ typedef std::vector<ExclusionRule> ExclusionRuleList;
+
+ MapRuleList map_rules_;
+ ExclusionRuleList exclusion_rules_;
+
+ DISALLOW_COPY_AND_ASSIGN(HostMappingRules);
+};
+
+} // namespace net
+
+#endif // NET_BASE_HOST_MAPPING_RULES_H_