Chromium Code Reviews| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 } | 77 } |
| 77 NOTREACHED(); | 78 NOTREACHED(); |
| 78 return false; | 79 return false; |
| 79 } | 80 } |
| 80 | 81 |
| 81 std::string AlternativeService::ToString() const { | 82 std::string AlternativeService::ToString() const { |
| 82 return base::StringPrintf("%s %s:%d", NextProtoToString(protocol), | 83 return base::StringPrintf("%s %s:%d", NextProtoToString(protocol), |
| 83 host.c_str(), port); | 84 host.c_str(), port); |
| 84 } | 85 } |
| 85 | 86 |
| 87 bool AlternativeService::FromString(const std::string& str, | |
| 88 AlternativeService* alternative_service) { | |
| 89 size_t space_pos = str.find(' '); | |
| 90 if (space_pos == std::string::npos) | |
| 91 return false; | |
| 92 size_t colon_pos = str.find(':'); | |
| 93 if (colon_pos == std::string::npos) | |
| 94 return false; | |
| 95 | |
| 96 alternative_service->protocol = NextProtoFromString(str.substr(0, space_pos)); | |
| 97 alternative_service->host = | |
| 98 str.substr(space_pos + 1, colon_pos - space_pos - 1); | |
| 99 | |
| 100 unsigned port_uint; | |
| 101 if (!base::StringToUint(str.substr(colon_pos + 1), &port_uint)) | |
| 102 return false; | |
| 103 if (port_uint > std::numeric_limits<uint16_t>::max()) | |
| 104 return false; | |
| 105 alternative_service->port = (uint16_t)port_uint; | |
| 106 | |
| 107 return true; | |
| 108 } | |
|
Ryan Hamilton
2017/06/12 18:57:32
Tests?
wangyix1
2017/06/14 00:01:25
Where should the test for this go? There doesn't s
| |
| 109 | |
| 86 std::string AlternativeServiceInfo::ToString() const { | 110 std::string AlternativeServiceInfo::ToString() const { |
| 87 base::Time::Exploded exploded; | 111 base::Time::Exploded exploded; |
| 88 expiration.LocalExplode(&exploded); | 112 expiration.LocalExplode(&exploded); |
| 89 return base::StringPrintf( | 113 return base::StringPrintf( |
| 90 "%s, expires %04d-%02d-%02d %02d:%02d:%02d", | 114 "%s, expires %04d-%02d-%02d %02d:%02d:%02d", |
| 91 alternative_service.ToString().c_str(), exploded.year, exploded.month, | 115 alternative_service.ToString().c_str(), exploded.year, exploded.month, |
| 92 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second); | 116 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second); |
| 93 } | 117 } |
| 94 | 118 |
| 95 std::ostream& operator<<(std::ostream& os, | 119 std::ostream& operator<<(std::ostream& os, |
| 96 const AlternativeService& alternative_service) { | 120 const AlternativeService& alternative_service) { |
| 97 os << alternative_service.ToString(); | 121 os << alternative_service.ToString(); |
| 98 return os; | 122 return os; |
| 99 } | 123 } |
| 100 | 124 |
| 101 // static | 125 // static |
| 102 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) { | 126 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) { |
| 103 ssl_config->alpn_protos.clear(); | 127 ssl_config->alpn_protos.clear(); |
| 104 ssl_config->alpn_protos.push_back(kProtoHTTP11); | 128 ssl_config->alpn_protos.push_back(kProtoHTTP11); |
| 105 } | 129 } |
| 106 | 130 |
| 107 } // namespace net | 131 } // namespace net |
| OLD | NEW |