OLD | NEW |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 AlternativeServiceInfoVector alternative_service_info_vector; | 44 AlternativeServiceInfoVector alternative_service_info_vector; |
45 for (const SpdyAltSvcWireFormat::AlternativeService& | 45 for (const SpdyAltSvcWireFormat::AlternativeService& |
46 alternative_service_entry : alternative_service_vector) { | 46 alternative_service_entry : alternative_service_vector) { |
47 NextProto protocol = | 47 NextProto protocol = |
48 NextProtoFromString(alternative_service_entry.protocol_id); | 48 NextProtoFromString(alternative_service_entry.protocol_id); |
49 if (!IsAlternateProtocolValid(protocol) || | 49 if (!IsAlternateProtocolValid(protocol) || |
50 !session->IsProtocolEnabled(protocol) || | 50 !session->IsProtocolEnabled(protocol) || |
51 !IsPortValid(alternative_service_entry.port)) { | 51 !IsPortValid(alternative_service_entry.port)) { |
52 continue; | 52 continue; |
53 } | 53 } |
54 // Check if QUIC version is supported. | 54 // Check if QUIC version is supported. Filter supported QUIC versions. |
| 55 QuicVersionVector advertised_versions; |
55 if (protocol == kProtoQUIC && !alternative_service_entry.version.empty()) { | 56 if (protocol == kProtoQUIC && !alternative_service_entry.version.empty()) { |
56 bool match_found = false; | 57 bool match_found = false; |
57 for (QuicVersion supported : session->params().quic_supported_versions) { | 58 for (QuicVersion supported : session->params().quic_supported_versions) { |
58 for (uint16_t advertised : alternative_service_entry.version) { | 59 for (uint16_t advertised : alternative_service_entry.version) { |
59 if (supported == advertised) { | 60 if (supported == advertised) { |
60 match_found = true; | 61 match_found = true; |
61 break; | 62 advertised_versions.push_back(supported); |
62 } | 63 } |
63 } | 64 } |
64 if (match_found) { | |
65 break; | |
66 } | |
67 } | 65 } |
68 if (!match_found) { | 66 if (!match_found) { |
69 continue; | 67 continue; |
70 } | 68 } |
71 } | 69 } |
72 AlternativeService alternative_service(protocol, | 70 AlternativeService alternative_service(protocol, |
73 alternative_service_entry.host, | 71 alternative_service_entry.host, |
74 alternative_service_entry.port); | 72 alternative_service_entry.port); |
75 base::Time expiration = | 73 base::Time expiration = |
76 base::Time::Now() + | 74 base::Time::Now() + |
77 base::TimeDelta::FromSeconds(alternative_service_entry.max_age); | 75 base::TimeDelta::FromSeconds(alternative_service_entry.max_age); |
78 AlternativeServiceInfo alternative_service_info(alternative_service, | 76 AlternativeServiceInfo alternative_service_info( |
79 expiration); | 77 alternative_service, expiration, advertised_versions); |
80 alternative_service_info_vector.push_back(alternative_service_info); | 78 alternative_service_info_vector.push_back(alternative_service_info); |
81 } | 79 } |
82 | 80 |
83 session->http_server_properties()->SetAlternativeServices( | 81 session->http_server_properties()->SetAlternativeServices( |
84 RewriteHost(http_server), alternative_service_info_vector); | 82 RewriteHost(http_server), alternative_service_info_vector); |
85 } | 83 } |
86 | 84 |
87 HttpStreamFactory::HttpStreamFactory() {} | 85 HttpStreamFactory::HttpStreamFactory() {} |
88 | 86 |
89 url::SchemeHostPort HttpStreamFactory::RewriteHost( | 87 url::SchemeHostPort HttpStreamFactory::RewriteHost( |
90 const url::SchemeHostPort& server) { | 88 const url::SchemeHostPort& server) { |
91 HostPortPair host_port_pair(server.host(), server.port()); | 89 HostPortPair host_port_pair(server.host(), server.port()); |
92 const HostMappingRules* mapping_rules = GetHostMappingRules(); | 90 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
93 if (mapping_rules) | 91 if (mapping_rules) |
94 mapping_rules->RewriteHost(&host_port_pair); | 92 mapping_rules->RewriteHost(&host_port_pair); |
95 return url::SchemeHostPort(server.scheme(), host_port_pair.host(), | 93 return url::SchemeHostPort(server.scheme(), host_port_pair.host(), |
96 host_port_pair.port()); | 94 host_port_pair.port()); |
97 } | 95 } |
98 | 96 |
99 } // namespace net | 97 } // namespace net |
OLD | NEW |