diff options
| author | smikler <[email protected]> | 2022-02-10 16:49:32 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:49:32 +0300 | 
| commit | e4f0fd4ab53ca40eb91e750cf3e7f76c21e930db (patch) | |
| tree | afee3c8173a0960bf439959f26e7624d1212e11a /library/cpp/string_utils/url/url.cpp | |
| parent | 1503061b80644305b2e6dd1327b57118e35ebd31 (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/string_utils/url/url.cpp')
| -rw-r--r-- | library/cpp/string_utils/url/url.cpp | 68 | 
1 files changed, 34 insertions, 34 deletions
diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp index 85f4ac5d693..579d1e25be4 100644 --- a/library/cpp/string_utils/url/url.cpp +++ b/library/cpp/string_utils/url/url.cpp @@ -147,41 +147,41 @@ static inline TStringBuf GetHostAndPortImpl(const TStringBuf url) {  }  TStringBuf GetHost(const TStringBuf url) noexcept { -    return GetHostAndPortImpl<false>(url); -} - +    return GetHostAndPortImpl<false>(url);  +}  +   TStringBuf GetHostAndPort(const TStringBuf url) noexcept { -    return GetHostAndPortImpl<true>(url); -} - +    return GetHostAndPortImpl<true>(url);  +}  +   TStringBuf GetSchemeHostAndPort(const TStringBuf url, bool trimHttp, bool trimDefaultPort) noexcept { -    const size_t schemeSize = GetSchemePrefixSize(url); -    const TStringBuf scheme = url.Head(schemeSize); - +    const size_t schemeSize = GetSchemePrefixSize(url);  +    const TStringBuf scheme = url.Head(schemeSize);  +       const bool isHttp = (schemeSize == 0 || scheme == TStringBuf("http://")); - -    TStringBuf hostAndPort = GetHostAndPort(url.Tail(schemeSize)); - -    if (trimDefaultPort) { -        const size_t pos = hostAndPort.find(':'); -        if (pos != TStringBuf::npos) { +  +    TStringBuf hostAndPort = GetHostAndPort(url.Tail(schemeSize));  +  +    if (trimDefaultPort) {  +        const size_t pos = hostAndPort.find(':');  +        if (pos != TStringBuf::npos) {               const bool isHttps = (scheme == TStringBuf("https://")); - -            const TStringBuf port = hostAndPort.Tail(pos + 1); +  +            const TStringBuf port = hostAndPort.Tail(pos + 1);               if ((isHttp && port == TStringBuf("80")) || (isHttps && port == TStringBuf("443"))) { -                // trimming default port -                hostAndPort = hostAndPort.Head(pos); -            } -        } -    } - -    if (isHttp && trimHttp) { -        return hostAndPort; -    } else { -        return TStringBuf(scheme.begin(), hostAndPort.end()); -    } -} - +                // trimming default port  +                hostAndPort = hostAndPort.Head(pos);  +            }  +        }  +    }  +  +    if (isHttp && trimHttp) {  +        return hostAndPort;  +    } else {  +        return TStringBuf(scheme.begin(), hostAndPort.end());  +    }  +}  +   void SplitUrlToHostAndPath(const TStringBuf url, TStringBuf& host, TStringBuf& path) {      auto [hostBuf, pathBuf] = NUrl::SplitUrlToHostAndPath(url);      host = hostBuf; @@ -240,14 +240,14 @@ TStringBuf GetOnlyHost(const TStringBuf url) noexcept {  }  TStringBuf GetPathAndQuery(const TStringBuf url, bool trimFragment) noexcept { -    const size_t off = url.find('/', GetHttpPrefixSize(url)); +    const size_t off = url.find('/', GetHttpPrefixSize(url));       TStringBuf hostUnused, path;      if (!url.TrySplitAt(off, hostUnused, path)) -        return "/"; +        return "/";       return trimFragment ? path.Before('#') : path; -} - +}  +   // this strange creature returns 2nd level domain, possibly with port  TStringBuf GetDomain(const TStringBuf host) noexcept {      const char* c = !host ? host.data() : host.end() - 1;  | 
