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/string_number_conversions.h" |
9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
10 #include "net/socket/ssl_client_socket.h" | 11 #include "net/socket/ssl_client_socket.h" |
11 #include "net/ssl/ssl_config.h" | 12 #include "net/ssl/ssl_config.h" |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 enum AlternativeProxyUsage { | 18 enum AlternativeProxyUsage { |
18 // Alternative Proxy was used without racing a normal connection. | 19 // Alternative Proxy was used without racing a normal connection. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 const AlternativeServiceInfo& alternative_service_info) = default; | 96 const AlternativeServiceInfo& alternative_service_info) = default; |
96 | 97 |
97 AlternativeServiceInfo& AlternativeServiceInfo::operator=( | 98 AlternativeServiceInfo& AlternativeServiceInfo::operator=( |
98 const AlternativeServiceInfo& alternative_service_info) = default; | 99 const AlternativeServiceInfo& alternative_service_info) = default; |
99 | 100 |
100 std::string AlternativeService::ToString() const { | 101 std::string AlternativeService::ToString() const { |
101 return base::StringPrintf("%s %s:%d", NextProtoToString(protocol), | 102 return base::StringPrintf("%s %s:%d", NextProtoToString(protocol), |
102 host.c_str(), port); | 103 host.c_str(), port); |
103 } | 104 } |
104 | 105 |
| 106 bool AlternativeService::FromString(const std::string& str, |
| 107 AlternativeService* alternative_service) { |
| 108 size_t space_pos = str.find(' '); |
| 109 if (space_pos == std::string::npos) |
| 110 return false; |
| 111 size_t colon_pos = str.find(':'); |
| 112 if (colon_pos == std::string::npos) |
| 113 return false; |
| 114 |
| 115 alternative_service->protocol = NextProtoFromString(str.substr(0, space_pos)); |
| 116 alternative_service->host = |
| 117 str.substr(space_pos + 1, colon_pos - space_pos - 1); |
| 118 |
| 119 unsigned port_uint; |
| 120 if (!base::StringToUint(str.substr(colon_pos + 1), &port_uint)) |
| 121 return false; |
| 122 if (port_uint > std::numeric_limits<uint16_t>::max()) |
| 123 return false; |
| 124 alternative_service->port = (uint16_t)port_uint; |
| 125 |
| 126 return true; |
| 127 } |
| 128 |
105 std::string AlternativeServiceInfo::ToString() const { | 129 std::string AlternativeServiceInfo::ToString() const { |
106 base::Time::Exploded exploded; | 130 base::Time::Exploded exploded; |
107 expiration_.LocalExplode(&exploded); | 131 expiration_.LocalExplode(&exploded); |
108 return base::StringPrintf( | 132 return base::StringPrintf( |
109 "%s, expires %04d-%02d-%02d %02d:%02d:%02d", | 133 "%s, expires %04d-%02d-%02d %02d:%02d:%02d", |
110 alternative_service_.ToString().c_str(), exploded.year, exploded.month, | 134 alternative_service_.ToString().c_str(), exploded.year, exploded.month, |
111 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second); | 135 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second); |
112 } | 136 } |
113 | 137 |
114 std::ostream& operator<<(std::ostream& os, | 138 std::ostream& operator<<(std::ostream& os, |
115 const AlternativeService& alternative_service) { | 139 const AlternativeService& alternative_service) { |
116 os << alternative_service.ToString(); | 140 os << alternative_service.ToString(); |
117 return os; | 141 return os; |
118 } | 142 } |
119 | 143 |
120 // static | 144 // static |
121 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) { | 145 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) { |
122 ssl_config->alpn_protos.clear(); | 146 ssl_config->alpn_protos.clear(); |
123 ssl_config->alpn_protos.push_back(kProtoHTTP11); | 147 ssl_config->alpn_protos.push_back(kProtoHTTP11); |
124 } | 148 } |
125 | 149 |
126 } // namespace net | 150 } // namespace net |
OLD | NEW |