| 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_server_properties.h" | 5 #include "net/http/http_server_properties.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "net/socket/ssl_client_socket.h" | 10 #include "net/socket/ssl_client_socket.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 ALTERNATE_PROTOCOL_USAGE_MAX); | 56 ALTERNATE_PROTOCOL_USAGE_MAX); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 void HistogramBrokenAlternateProtocolLocation( | 60 void HistogramBrokenAlternateProtocolLocation( |
| 61 BrokenAlternateProtocolLocation location){ | 61 BrokenAlternateProtocolLocation location){ |
| 62 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolBrokenLocation", location, | 62 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolBrokenLocation", location, |
| 63 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX); | 63 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX); |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool IsAlternateProtocolValid(AlternateProtocol protocol) { | 66 bool IsAlternateProtocolValid(NextProto protocol) { |
| 67 switch (protocol) { | 67 switch (protocol) { |
| 68 case NPN_HTTP_2: | 68 case kProtoUnknown: |
| 69 return false; |
| 70 case kProtoHTTP11: |
| 71 return false; |
| 72 case kProtoHTTP2: |
| 69 return true; | 73 return true; |
| 70 case QUIC: | 74 case kProtoQUIC: |
| 71 return true; | 75 return true; |
| 72 case UNINITIALIZED_ALTERNATE_PROTOCOL: | |
| 73 return false; | |
| 74 } | 76 } |
| 75 NOTREACHED(); | 77 NOTREACHED(); |
| 76 return false; | 78 return false; |
| 77 } | 79 } |
| 78 | 80 |
| 79 const char* AlternateProtocolToString(AlternateProtocol protocol) { | |
| 80 switch (protocol) { | |
| 81 case QUIC: | |
| 82 return "quic"; | |
| 83 case NPN_HTTP_2: | |
| 84 return "h2"; | |
| 85 case UNINITIALIZED_ALTERNATE_PROTOCOL: | |
| 86 return "Uninitialized"; | |
| 87 } | |
| 88 NOTREACHED(); | |
| 89 return ""; | |
| 90 } | |
| 91 | |
| 92 AlternateProtocol AlternateProtocolFromString(const std::string& str) { | |
| 93 if (str == "quic") | |
| 94 return QUIC; | |
| 95 if (str == "h2") | |
| 96 return NPN_HTTP_2; | |
| 97 // "npn-h2" and "npn-spdy/3.1" are accepted here so that persisted settings | |
| 98 // with the old string can be loaded from disk. TODO(bnc): Remove around | |
| 99 // 2016 December. | |
| 100 if (str == "npn-h2") | |
| 101 return NPN_HTTP_2; | |
| 102 if (str == "npn-spdy/3.1") | |
| 103 return NPN_HTTP_2; | |
| 104 | |
| 105 return UNINITIALIZED_ALTERNATE_PROTOCOL; | |
| 106 } | |
| 107 | |
| 108 AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) { | |
| 109 switch (next_proto) { | |
| 110 case kProtoHTTP2: | |
| 111 return NPN_HTTP_2; | |
| 112 case kProtoQUIC: | |
| 113 return QUIC; | |
| 114 | |
| 115 case kProtoUnknown: | |
| 116 case kProtoHTTP11: | |
| 117 break; | |
| 118 } | |
| 119 | |
| 120 NOTREACHED() << "Invalid NextProto: " << next_proto; | |
| 121 return UNINITIALIZED_ALTERNATE_PROTOCOL; | |
| 122 } | |
| 123 | |
| 124 std::string AlternativeService::ToString() const { | 81 std::string AlternativeService::ToString() const { |
| 125 return base::StringPrintf("%s %s:%d", AlternateProtocolToString(protocol), | 82 return base::StringPrintf("%s %s:%d", NextProtoToString(protocol), |
| 126 host.c_str(), port); | 83 host.c_str(), port); |
| 127 } | 84 } |
| 128 | 85 |
| 129 std::string AlternativeServiceInfo::ToString() const { | 86 std::string AlternativeServiceInfo::ToString() const { |
| 130 base::Time::Exploded exploded; | 87 base::Time::Exploded exploded; |
| 131 expiration.LocalExplode(&exploded); | 88 expiration.LocalExplode(&exploded); |
| 132 return base::StringPrintf( | 89 return base::StringPrintf( |
| 133 "%s, expires %04d-%02d-%02d %02d:%02d:%02d", | 90 "%s, expires %04d-%02d-%02d %02d:%02d:%02d", |
| 134 alternative_service.ToString().c_str(), exploded.year, exploded.month, | 91 alternative_service.ToString().c_str(), exploded.year, exploded.month, |
| 135 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second); | 92 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second); |
| 136 } | 93 } |
| 137 | 94 |
| 138 // static | 95 // static |
| 139 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) { | 96 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) { |
| 140 ssl_config->alpn_protos.clear(); | 97 ssl_config->alpn_protos.clear(); |
| 141 ssl_config->alpn_protos.push_back(kProtoHTTP11); | 98 ssl_config->alpn_protos.push_back(kProtoHTTP11); |
| 142 } | 99 } |
| 143 | 100 |
| 144 } // namespace net | 101 } // namespace net |
| OLD | NEW |