| 208 | } |
| 209 | |
| 210 | TStringBuf GetSchemeHostAndPort(const TStringBuf url Y_LIFETIME_BOUND, bool trimHttp, bool trimDefaultPort) noexcept { |
| 211 | const size_t schemeSize = GetSchemePrefixSize(url); |
| 212 | const TStringBuf scheme = url.Head(schemeSize); |
| 213 | |
| 214 | const bool isHttp = (schemeSize == 0 || scheme == TStringBuf("http://")); |
| 215 | |
| 216 | TStringBuf hostAndPort = GetHostAndPort(url.Tail(schemeSize)); |
| 217 | |
| 218 | if (trimDefaultPort) { |
| 219 | const size_t pos = hostAndPort.find(':'); |
| 220 | if (pos != TStringBuf::npos) { |
| 221 | const bool isHttps = (scheme == TStringBuf("https://")); |
| 222 | |
| 223 | const TStringBuf port = hostAndPort.Tail(pos + 1); |
| 224 | if ((isHttp && port == TStringBuf("80")) || (isHttps && port == TStringBuf("443"))) { |
| 225 | // trimming default port |
| 226 | hostAndPort = hostAndPort.Head(pos); |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if (isHttp && trimHttp) { |
| 232 | return hostAndPort; |
| 233 | } else { |
| 234 | return TStringBuf(scheme.begin(), hostAndPort.end()); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | void SplitUrlToHostAndPath(const TStringBuf url, TStringBuf& host, TStringBuf& path) { |
| 239 | auto [hostBuf, pathBuf] = NUrl::SplitUrlToHostAndPath(url); |
no test coverage detected