Chromium Code Reviews| Index: net/http/http_server_properties.cc |
| diff --git a/net/http/http_server_properties.cc b/net/http/http_server_properties.cc |
| index 386a00d0fe3e53c356865c2ce47088f3e245e1b0..3d594176e68656bb1f7ed74ca12322bdf52a4513 100644 |
| --- a/net/http/http_server_properties.cc |
| +++ b/net/http/http_server_properties.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/logging.h" |
| #include "base/metrics/histogram_macros.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "base/strings/stringprintf.h" |
| #include "net/socket/ssl_client_socket.h" |
| #include "net/ssl/ssl_config.h" |
| @@ -83,6 +84,29 @@ std::string AlternativeService::ToString() const { |
| host.c_str(), port); |
| } |
| +bool AlternativeService::FromString(const std::string& str, |
| + AlternativeService* alternative_service) { |
| + size_t space_pos = str.find(' '); |
| + if (space_pos == std::string::npos) |
| + return false; |
| + size_t colon_pos = str.find(':'); |
| + if (colon_pos == std::string::npos) |
| + return false; |
| + |
| + alternative_service->protocol = NextProtoFromString(str.substr(0, space_pos)); |
| + alternative_service->host = |
| + str.substr(space_pos + 1, colon_pos - space_pos - 1); |
| + |
| + unsigned port_uint; |
| + if (!base::StringToUint(str.substr(colon_pos + 1), &port_uint)) |
| + return false; |
| + if (port_uint > std::numeric_limits<uint16_t>::max()) |
| + return false; |
| + alternative_service->port = (uint16_t)port_uint; |
| + |
| + return true; |
| +} |
|
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
|
| + |
| std::string AlternativeServiceInfo::ToString() const { |
| base::Time::Exploded exploded; |
| expiration.LocalExplode(&exploded); |