| 163 | |
| 164 | template <bool KeepPort> |
| 165 | static inline TStringBuf GetHostAndPortImpl(const TStringBuf url) { |
| 166 | TStringBuf urlNoScheme = url; |
| 167 | |
| 168 | urlNoScheme.Skip(GetHttpPrefixSize(url)); |
| 169 | |
| 170 | struct TDelim: public str_spn { |
| 171 | inline TDelim() |
| 172 | : str_spn(KeepPort ? "/;?#" : "/:;?#") |
| 173 | { |
| 174 | } |
| 175 | }; |
| 176 | |
| 177 | const auto& nonHostCharacters = *Singleton<TDelim>(); |
| 178 | const char* firstNonHostCharacter = nonHostCharacters.brk(urlNoScheme.begin(), urlNoScheme.end()); |
| 179 | |
| 180 | if (firstNonHostCharacter != urlNoScheme.end()) { |
| 181 | return urlNoScheme.substr(0, firstNonHostCharacter - urlNoScheme.data()); |
| 182 | } |
| 183 | |
| 184 | return urlNoScheme; |
| 185 | } |
| 186 | |
| 187 | TStringBuf GetHost(const TStringBuf url Y_LIFETIME_BOUND) noexcept { |
| 188 | return GetHostAndPortImpl<false>(url); |