| // Copyright 2013 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "net/base/url_util.h" |
| |
| #include "build/build_config.h" |
| |
| #if defined(OS_POSIX) |
| #include <netinet/in.h> |
| #elif defined(OS_WIN) |
| #include <ws2tcpip.h> |
| #endif |
| |
| #include "url/url_canon.h" |
| #include "url/url_canon_stdstring.h" |
| |
| namespace url { |
| namespace net { |
| |
| std::string CanonicalizeHost(base::StringPiece host, |
| url::CanonHostInfo* host_info) { |
| // Try to canonicalize the host. |
| const url::Component raw_host_component(0, static_cast<int>(host.length())); |
| std::string canon_host; |
| url::StdStringCanonOutput canon_host_output(&canon_host); |
| url::CanonicalizeHostVerbose(host.data(), raw_host_component, |
| &canon_host_output, host_info); |
| |
| if (host_info->out_host.is_nonempty() && |
| host_info->family != url::CanonHostInfo::BROKEN) { |
| // Success! Assert that there's no extra garbage. |
| canon_host_output.Complete(); |
| DCHECK_EQ(host_info->out_host.len, static_cast<int>(canon_host.length())); |
| } else { |
| // Empty host, or canonicalization failed. We'll return empty. |
| canon_host.clear(); |
| } |
| |
| return canon_host; |
| } |
| |
| } // namespace net |
| } // namespace url |