| 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 if (protocol == kProtoQUIC) { |
| 78 alternative_service_info = |
| 79 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 80 alternative_service, expiration, advertised_versions); |
| 81 } else { |
| 82 alternative_service_info = |
| 83 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo( |
| 84 alternative_service, expiration); |
| 85 } |
| 80 alternative_service_info_vector.push_back(alternative_service_info); | 86 alternative_service_info_vector.push_back(alternative_service_info); |
| 81 } | 87 } |
| 82 | 88 |
| 83 session->http_server_properties()->SetAlternativeServices( | 89 session->http_server_properties()->SetAlternativeServices( |
| 84 RewriteHost(http_server), alternative_service_info_vector); | 90 RewriteHost(http_server), alternative_service_info_vector); |
| 85 } | 91 } |
| 86 | 92 |
| 87 HttpStreamFactory::HttpStreamFactory() {} | 93 HttpStreamFactory::HttpStreamFactory() {} |
| 88 | 94 |
| 89 url::SchemeHostPort HttpStreamFactory::RewriteHost( | 95 url::SchemeHostPort HttpStreamFactory::RewriteHost( |
| 90 const url::SchemeHostPort& server) { | 96 const url::SchemeHostPort& server) { |
| 91 HostPortPair host_port_pair(server.host(), server.port()); | 97 HostPortPair host_port_pair(server.host(), server.port()); |
| 92 const HostMappingRules* mapping_rules = GetHostMappingRules(); | 98 const HostMappingRules* mapping_rules = GetHostMappingRules(); |
| 93 if (mapping_rules) | 99 if (mapping_rules) |
| 94 mapping_rules->RewriteHost(&host_port_pair); | 100 mapping_rules->RewriteHost(&host_port_pair); |
| 95 return url::SchemeHostPort(server.scheme(), host_port_pair.host(), | 101 return url::SchemeHostPort(server.scheme(), host_port_pair.host(), |
| 96 host_port_pair.port()); | 102 host_port_pair.port()); |
| 97 } | 103 } |
| 98 | 104 |
| 99 } // namespace net | 105 } // namespace net |
| OLD | NEW |