| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_impl_job_controller.h" | 5 #include "net/http/http_stream_factory_impl_job_controller.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "net/base/host_mapping_rules.h" | 10 #include "net/base/host_mapping_rules.h" |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 HttpServerProperties& http_server_properties = | 719 HttpServerProperties& http_server_properties = |
| 720 *session_->http_server_properties(); | 720 *session_->http_server_properties(); |
| 721 const AlternativeServiceVector alternative_service_vector = | 721 const AlternativeServiceVector alternative_service_vector = |
| 722 http_server_properties.GetAlternativeServices(origin); | 722 http_server_properties.GetAlternativeServices(origin); |
| 723 if (alternative_service_vector.empty()) | 723 if (alternative_service_vector.empty()) |
| 724 return AlternativeService(); | 724 return AlternativeService(); |
| 725 | 725 |
| 726 bool quic_advertised = false; | 726 bool quic_advertised = false; |
| 727 bool quic_all_broken = true; | 727 bool quic_all_broken = true; |
| 728 | 728 |
| 729 const bool enable_different_host = | |
| 730 session_->params().enable_alternative_service_with_different_host; | |
| 731 | |
| 732 // First Alt-Svc that is not marked as broken. | 729 // First Alt-Svc that is not marked as broken. |
| 733 AlternativeService first_alternative_service; | 730 AlternativeService first_alternative_service; |
| 734 | 731 |
| 735 for (const AlternativeService& alternative_service : | 732 for (const AlternativeService& alternative_service : |
| 736 alternative_service_vector) { | 733 alternative_service_vector) { |
| 737 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); | 734 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); |
| 738 if (!quic_advertised && alternative_service.protocol == QUIC) | 735 if (!quic_advertised && alternative_service.protocol == QUIC) |
| 739 quic_advertised = true; | 736 quic_advertised = true; |
| 740 if (http_server_properties.IsAlternativeServiceBroken( | 737 if (http_server_properties.IsAlternativeServiceBroken( |
| 741 alternative_service)) { | 738 alternative_service)) { |
| 742 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); | 739 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); |
| 743 continue; | 740 continue; |
| 744 } | 741 } |
| 745 | 742 |
| 746 if (origin.host() != alternative_service.host && !enable_different_host) | |
| 747 continue; | |
| 748 | 743 |
| 749 // Some shared unix systems may have user home directories (like | 744 // Some shared unix systems may have user home directories (like |
| 750 // http://foo.com/~mike) which allow users to emit headers. This is a bad | 745 // http://foo.com/~mike) which allow users to emit headers. This is a bad |
| 751 // idea already, but with Alternate-Protocol, it provides the ability for a | 746 // idea already, but with Alternate-Protocol, it provides the ability for a |
| 752 // single user on a multi-user system to hijack the alternate protocol. | 747 // single user on a multi-user system to hijack the alternate protocol. |
| 753 // These systems also enforce ports <1024 as restricted ports. So don't | 748 // These systems also enforce ports <1024 as restricted ports. So don't |
| 754 // allow protocol upgrades to user-controllable ports. | 749 // allow protocol upgrades to user-controllable ports. |
| 755 const int kUnrestrictedPort = 1024; | 750 const int kUnrestrictedPort = 1024; |
| 756 if (!session_->params().enable_user_alternate_protocol_ports && | 751 if (!session_->params().enable_user_alternate_protocol_ports && |
| 757 (alternative_service.port >= kUnrestrictedPort && | 752 (alternative_service.port >= kUnrestrictedPort && |
| 758 origin.port() < kUnrestrictedPort)) | 753 origin.port() < kUnrestrictedPort)) |
| 759 continue; | 754 continue; |
| 760 | 755 |
| 761 if (alternative_service.protocol >= NPN_SPDY_MINIMUM_VERSION && | 756 if (alternative_service.protocol >= NPN_SPDY_MINIMUM_VERSION && |
| 762 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) { | 757 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) { |
| 763 if (!HttpStreamFactory::spdy_enabled()) | 758 if (!HttpStreamFactory::spdy_enabled()) |
| 764 continue; | 759 continue; |
| 765 | 760 |
| 766 // TODO(bnc): Re-enable when https://crbug.com/615413 is fixed. | 761 if (origin.host() != alternative_service.host && |
| 767 if (origin.host() != alternative_service.host) | 762 !session_->params() |
| 763 .enable_http2_alternative_service_with_different_host) { |
| 768 continue; | 764 continue; |
| 765 } |
| 769 | 766 |
| 770 // Cache this entry if we don't have a non-broken Alt-Svc yet. | 767 // Cache this entry if we don't have a non-broken Alt-Svc yet. |
| 771 if (first_alternative_service.protocol == | 768 if (first_alternative_service.protocol == |
| 772 UNINITIALIZED_ALTERNATE_PROTOCOL) | 769 UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 773 first_alternative_service = alternative_service; | 770 first_alternative_service = alternative_service; |
| 774 continue; | 771 continue; |
| 775 } | 772 } |
| 776 | 773 |
| 777 DCHECK_EQ(QUIC, alternative_service.protocol); | 774 DCHECK_EQ(QUIC, alternative_service.protocol); |
| 775 if (origin.host() != alternative_service.host && |
| 776 !session_->params() |
| 777 .enable_quic_alternative_service_with_different_host) { |
| 778 continue; |
| 779 } |
| 780 |
| 778 quic_all_broken = false; | 781 quic_all_broken = false; |
| 779 if (!session_->params().enable_quic) | 782 if (!session_->params().enable_quic) |
| 780 continue; | 783 continue; |
| 781 | 784 |
| 782 if (!IsQuicWhitelistedForHost(origin.host())) | 785 if (!IsQuicWhitelistedForHost(origin.host())) |
| 783 continue; | 786 continue; |
| 784 | 787 |
| 785 if (stream_type == HttpStreamRequest::BIDIRECTIONAL_STREAM && | 788 if (stream_type == HttpStreamRequest::BIDIRECTIONAL_STREAM && |
| 786 session_->params().quic_disable_bidirectional_streams) { | 789 session_->params().quic_disable_bidirectional_streams) { |
| 787 continue; | 790 continue; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 812 first_alternative_service = alternative_service; | 815 first_alternative_service = alternative_service; |
| 813 } | 816 } |
| 814 | 817 |
| 815 // Ask delegate to mark QUIC as broken for the origin. | 818 // Ask delegate to mark QUIC as broken for the origin. |
| 816 if (quic_advertised && quic_all_broken && delegate != nullptr) | 819 if (quic_advertised && quic_all_broken && delegate != nullptr) |
| 817 delegate->OnQuicBroken(); | 820 delegate->OnQuicBroken(); |
| 818 | 821 |
| 819 return first_alternative_service; | 822 return first_alternative_service; |
| 820 } | 823 } |
| 821 } | 824 } |
| OLD | NEW |