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

Side by Side Diff: net/http/http_stream_factory.cc

Issue 1014043004: Clear alternate protocols on empty or invalid header (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix in response to broken test Created 5 years, 9 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
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/http/http_stream_factory.h" 5 #include "net/http/http_stream_factory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 18 matching lines...) Expand all
29 } 29 }
30 30
31 void HttpStreamFactory::ProcessAlternateProtocol( 31 void HttpStreamFactory::ProcessAlternateProtocol(
32 const base::WeakPtr<HttpServerProperties>& http_server_properties, 32 const base::WeakPtr<HttpServerProperties>& http_server_properties,
33 const std::vector<std::string>& alternate_protocol_values, 33 const std::vector<std::string>& alternate_protocol_values,
34 const HostPortPair& http_host_port_pair, 34 const HostPortPair& http_host_port_pair,
35 const HttpNetworkSession& session) { 35 const HttpNetworkSession& session) {
36 AlternateProtocol protocol = UNINITIALIZED_ALTERNATE_PROTOCOL; 36 AlternateProtocol protocol = UNINITIALIZED_ALTERNATE_PROTOCOL;
37 int port = 0; 37 int port = 0;
38 double probability = 1; 38 double probability = 1;
39 bool is_valid = true;
39 for (size_t i = 0; i < alternate_protocol_values.size(); ++i) { 40 for (size_t i = 0; i < alternate_protocol_values.size(); ++i) {
40 const std::string& alternate_protocol_str = alternate_protocol_values[i]; 41 const std::string& alternate_protocol_str = alternate_protocol_values[i];
41 if (StartsWithASCII(alternate_protocol_str, "p=", true)) { 42 if (StartsWithASCII(alternate_protocol_str, "p=", true)) {
42 if (!base::StringToDouble(alternate_protocol_str.substr(2), 43 if (!base::StringToDouble(alternate_protocol_str.substr(2),
43 &probability) || 44 &probability) ||
44 probability < 0 || probability > 1) { 45 probability < 0 || probability > 1) {
45 DVLOG(1) << kAlternateProtocolHeader 46 DVLOG(1) << kAlternateProtocolHeader
46 << " header has unrecognizable probability: " 47 << " header has unrecognizable probability: "
47 << alternate_protocol_values[i]; 48 << alternate_protocol_values[i];
48 return; 49 is_valid = false;
50 break;
49 } 51 }
50 continue; 52 continue;
51 } 53 }
52 54
53 std::vector<std::string> port_protocol_vector; 55 std::vector<std::string> port_protocol_vector;
54 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); 56 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector);
55 if (port_protocol_vector.size() != 2) { 57 if (port_protocol_vector.size() != 2) {
56 DVLOG(1) << kAlternateProtocolHeader 58 DVLOG(1) << kAlternateProtocolHeader
57 << " header has too many tokens: " 59 << " header has too many tokens: "
58 << alternate_protocol_str; 60 << alternate_protocol_str;
59 return; 61 is_valid = false;
62 break;
60 } 63 }
61 64
62 if (!base::StringToInt(port_protocol_vector[0], &port) || 65 if (!base::StringToInt(port_protocol_vector[0], &port) ||
63 port == 0 || !IsPortValid(port)) { 66 port == 0 || !IsPortValid(port)) {
64 DVLOG(1) << kAlternateProtocolHeader 67 DVLOG(1) << kAlternateProtocolHeader
65 << " header has unrecognizable port: " 68 << " header has unrecognizable port: "
66 << port_protocol_vector[0]; 69 << port_protocol_vector[0];
67 return; 70 is_valid = false;
71 break;
68 } 72 }
69 73
70 protocol = AlternateProtocolFromString(port_protocol_vector[1]); 74 protocol = AlternateProtocolFromString(port_protocol_vector[1]);
71 75
72 if (IsAlternateProtocolValid(protocol) && 76 if (IsAlternateProtocolValid(protocol) &&
73 !session.IsProtocolEnabled(protocol)) { 77 !session.IsProtocolEnabled(protocol)) {
74 DVLOG(1) << kAlternateProtocolHeader 78 DVLOG(1) << kAlternateProtocolHeader
75 << " header has unrecognized protocol: " 79 << " header has unrecognized protocol: "
76 << port_protocol_vector[1]; 80 << port_protocol_vector[1];
77 return; 81 is_valid = false;
82 break;
78 } 83 }
79 } 84 }
80 85
81 if (protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) 86 if (!is_valid || protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) {
87 http_server_properties->ClearAlternateProtocol(http_host_port_pair);
82 return; 88 return;
89 }
83 90
84 HostPortPair host_port(http_host_port_pair); 91 HostPortPair host_port(http_host_port_pair);
85 const HostMappingRules* mapping_rules = GetHostMappingRules(); 92 const HostMappingRules* mapping_rules = GetHostMappingRules();
86 if (mapping_rules) 93 if (mapping_rules)
87 mapping_rules->RewriteHost(&host_port); 94 mapping_rules->RewriteHost(&host_port);
88 95
89 http_server_properties->SetAlternateProtocol( 96 http_server_properties->SetAlternateProtocol(
90 host_port, static_cast<uint16>(port), protocol, probability); 97 host_port, static_cast<uint16>(port), protocol, probability);
91 } 98 }
92 99
93 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, 100 GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url,
94 HostPortPair* endpoint) { 101 HostPortPair* endpoint) {
95 const HostMappingRules* mapping_rules = GetHostMappingRules(); 102 const HostMappingRules* mapping_rules = GetHostMappingRules();
96 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { 103 if (mapping_rules && mapping_rules->RewriteHost(endpoint)) {
97 url::Replacements<char> replacements; 104 url::Replacements<char> replacements;
98 const std::string port_str = base::IntToString(endpoint->port()); 105 const std::string port_str = base::IntToString(endpoint->port());
99 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size())); 106 replacements.SetPort(port_str.c_str(), url::Component(0, port_str.size()));
100 replacements.SetHost(endpoint->host().c_str(), 107 replacements.SetHost(endpoint->host().c_str(),
101 url::Component(0, endpoint->host().size())); 108 url::Component(0, endpoint->host().size()));
102 return url.ReplaceComponents(replacements); 109 return url.ReplaceComponents(replacements);
103 } 110 }
104 return url; 111 return url;
105 } 112 }
106 113
107 HttpStreamFactory::HttpStreamFactory() {} 114 HttpStreamFactory::HttpStreamFactory() {}
108 115
109 } // namespace net 116 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698