MCPcopy Create free account
hub / github.com/catboost/catboost / GetSchemeHostAndPort

Function GetSchemeHostAndPort

library/cpp/string_utils/url/url.cpp:210–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208}
209
210TStringBuf 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
238void SplitUrlToHostAndPath(const TStringBuf url, TStringBuf& host, TStringBuf& path) {
239 auto [hostBuf, pathBuf] = NUrl::SplitUrlToHostAndPath(url);

Callers 2

SplitUrlToHostAndPathFunction · 0.85
Y_UNIT_TESTFunction · 0.85

Calls 8

GetSchemePrefixSizeFunction · 0.85
GetHostAndPortFunction · 0.85
TryGetSchemeHostAndPortFunction · 0.85
TailMethod · 0.80
HeadMethod · 0.45
findMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected