| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_network_layer.h" | 5 #include "net/http/http_network_layer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // We want an A/B experiment between SPDY enabled and SPDY disabled, | 59 // We want an A/B experiment between SPDY enabled and SPDY disabled, |
| 60 // but only for pages where SPDY *could have been* negotiated. To do | 60 // but only for pages where SPDY *could have been* negotiated. To do |
| 61 // this, we use NPN, but prevent it from negotiating SPDY. If the | 61 // this, we use NPN, but prevent it from negotiating SPDY. If the |
| 62 // server negotiates HTTP, rather than SPDY, today that will only happen | 62 // server negotiates HTTP, rather than SPDY, today that will only happen |
| 63 // on servers that installed NPN (and could have done SPDY). But this is | 63 // on servers that installed NPN (and could have done SPDY). But this is |
| 64 // a bit of a hack, as this correlation between NPN and SPDY is not | 64 // a bit of a hack, as this correlation between NPN and SPDY is not |
| 65 // really guaranteed. | 65 // really guaranteed. |
| 66 static const char kEnableNPN[] = "npn"; | 66 static const char kEnableNPN[] = "npn"; |
| 67 static const char kEnableNpnHttpOnly[] = "npn-http"; | 67 static const char kEnableNpnHttpOnly[] = "npn-http"; |
| 68 | 68 |
| 69 // Except for the first element, the order is irrelevant. First element | |
| 70 // specifies the fallback in case nothing matches | |
| 71 // (SSLClientSocket::kNextProtoNoOverlap). Otherwise, the SSL library | |
| 72 // will choose the first overlapping protocol in the server's list, since | |
| 73 // it presumedly has a better understanding of which protocol we should | |
| 74 // use, therefore the rest of the ordering here is not important. | |
| 75 static const char kNpnProtosFull[] = "\x08http/1.1\x06spdy/2"; | |
| 76 // This is a temporary hack to pretend we support version 1. | |
| 77 static const char kNpnProtosFullV1[] = "\x08http/1.1\x06spdy/1"; | |
| 78 // No spdy specified. | |
| 79 static const char kNpnProtosHttpOnly[] = "\x08http/1.1\x07http1.1"; | |
| 80 | |
| 81 static const char kInitialMaxConcurrentStreams[] = "init-max-streams"; | 69 static const char kInitialMaxConcurrentStreams[] = "init-max-streams"; |
| 82 | 70 |
| 83 std::vector<std::string> spdy_options; | 71 std::vector<std::string> spdy_options; |
| 84 base::SplitString(mode, ',', &spdy_options); | 72 base::SplitString(mode, ',', &spdy_options); |
| 85 | 73 |
| 86 bool use_alt_protocols = true; | 74 bool use_alt_protocols = true; |
| 87 | 75 |
| 88 for (std::vector<std::string>::iterator it = spdy_options.begin(); | 76 for (std::vector<std::string>::iterator it = spdy_options.begin(); |
| 89 it != spdy_options.end(); ++it) { | 77 it != spdy_options.end(); ++it) { |
| 90 const std::string& element = *it; | 78 const std::string& element = *it; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 103 HttpStreamFactory::set_force_spdy_over_ssl(true); | 91 HttpStreamFactory::set_force_spdy_over_ssl(true); |
| 104 HttpStreamFactory::set_force_spdy_always(true); | 92 HttpStreamFactory::set_force_spdy_always(true); |
| 105 } else if (option == kDisablePing) { | 93 } else if (option == kDisablePing) { |
| 106 SpdySession::set_enable_ping_based_connection_checking(false); | 94 SpdySession::set_enable_ping_based_connection_checking(false); |
| 107 } else if (option == kExclude) { | 95 } else if (option == kExclude) { |
| 108 HttpStreamFactory::add_forced_spdy_exclusion(value); | 96 HttpStreamFactory::add_forced_spdy_exclusion(value); |
| 109 } else if (option == kDisableCompression) { | 97 } else if (option == kDisableCompression) { |
| 110 spdy::SpdyFramer::set_enable_compression_default(false); | 98 spdy::SpdyFramer::set_enable_compression_default(false); |
| 111 } else if (option == kEnableNPN) { | 99 } else if (option == kEnableNPN) { |
| 112 HttpStreamFactory::set_use_alternate_protocols(use_alt_protocols); | 100 HttpStreamFactory::set_use_alternate_protocols(use_alt_protocols); |
| 113 HttpStreamFactory::set_next_protos(kNpnProtosFull); | 101 std::vector<std::string> next_protos; |
| 102 next_protos.push_back("http/1.1"); |
| 103 next_protos.push_back("spdy/2"); |
| 104 HttpStreamFactory::set_next_protos(next_protos); |
| 114 } else if (option == kEnableNpnHttpOnly) { | 105 } else if (option == kEnableNpnHttpOnly) { |
| 115 // Avoid alternate protocol in this case. Otherwise, browser will try SSL | 106 // Avoid alternate protocol in this case. Otherwise, browser will try SSL |
| 116 // and then fallback to http. This introduces extra load. | 107 // and then fallback to http. This introduces extra load. |
| 117 HttpStreamFactory::set_use_alternate_protocols(false); | 108 HttpStreamFactory::set_use_alternate_protocols(false); |
| 118 HttpStreamFactory::set_next_protos(kNpnProtosHttpOnly); | 109 std::vector<std::string> next_protos; |
| 110 next_protos.push_back("http/1.1"); |
| 111 next_protos.push_back("http1.1"); |
| 112 HttpStreamFactory::set_next_protos(next_protos); |
| 119 } else if (option == kEnableVersionOne) { | 113 } else if (option == kEnableVersionOne) { |
| 120 spdy::SpdyFramer::set_protocol_version(1); | 114 spdy::SpdyFramer::set_protocol_version(1); |
| 121 HttpStreamFactory::set_next_protos(kNpnProtosFullV1); | 115 std::vector<std::string> next_protos; |
| 116 // This is a temporary hack to pretend we support version 1. |
| 117 next_protos.push_back("http/1.1"); |
| 118 next_protos.push_back("spdy/1"); |
| 119 HttpStreamFactory::set_next_protos(next_protos); |
| 122 } else if (option == kDisableAltProtocols) { | 120 } else if (option == kDisableAltProtocols) { |
| 123 use_alt_protocols = false; | 121 use_alt_protocols = false; |
| 124 HttpStreamFactory::set_use_alternate_protocols(false); | 122 HttpStreamFactory::set_use_alternate_protocols(false); |
| 125 } else if (option == kEnableFlowControl) { | 123 } else if (option == kEnableFlowControl) { |
| 126 SpdySession::set_flow_control(true); | 124 SpdySession::set_flow_control(true); |
| 127 } else if (option == kForceAltProtocols) { | 125 } else if (option == kForceAltProtocols) { |
| 128 PortAlternateProtocolPair pair; | 126 PortAlternateProtocolPair pair; |
| 129 pair.port = 443; | 127 pair.port = 443; |
| 130 pair.protocol = NPN_SPDY_2; | 128 pair.protocol = NPN_SPDY_2; |
| 131 HttpServerPropertiesImpl::ForceAlternateProtocol(pair); | 129 HttpServerPropertiesImpl::ForceAlternateProtocol(pair); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 165 |
| 168 if (session_) | 166 if (session_) |
| 169 session_->CloseIdleConnections(); | 167 session_->CloseIdleConnections(); |
| 170 } | 168 } |
| 171 | 169 |
| 172 void HttpNetworkLayer::OnResume() { | 170 void HttpNetworkLayer::OnResume() { |
| 173 suspended_ = false; | 171 suspended_ = false; |
| 174 } | 172 } |
| 175 | 173 |
| 176 } // namespace net | 174 } // namespace net |
| OLD | NEW |