diff options
author | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
commit | 06e5c21a835c0e923506c4ff27929f34e00761c2 (patch) | |
tree | 75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/cpp/neh/location.cpp | |
parent | 03f024c4412e3aa613bb543cf1660176320ba8f4 (diff) | |
download | ydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz |
fix ya.make
Diffstat (limited to 'library/cpp/neh/location.cpp')
-rw-r--r-- | library/cpp/neh/location.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/library/cpp/neh/location.cpp b/library/cpp/neh/location.cpp new file mode 100644 index 00000000000..36c08466736 --- /dev/null +++ b/library/cpp/neh/location.cpp @@ -0,0 +1,50 @@ +#include "location.h" + +#include <util/string/cast.h> + +using namespace NNeh; + +TParsedLocation::TParsedLocation(TStringBuf path) { + path.Split(':', Scheme, path); + path.Skip(2); + + const size_t pos = path.find_first_of(TStringBuf("?@")); + + if (TStringBuf::npos != pos && '@' == path[pos]) { + path.SplitAt(pos, UserInfo, path); + path.Skip(1); + } + + auto checkRange = [](size_t b, size_t e){ + return b != TStringBuf::npos && e != TStringBuf::npos && b < e; + }; + + size_t oBracket = path.find_first_of('['); + size_t cBracket = path.find_first_of(']'); + size_t endEndPointPos = path.find_first_of('/'); + if (checkRange(oBracket, cBracket)) { + endEndPointPos = path.find_first_of('/', cBracket); + } + EndPoint = path.SubStr(0, endEndPointPos); + Host = EndPoint; + + size_t lastColon = EndPoint.find_last_of(':'); + if (checkRange(cBracket, lastColon) + || (cBracket == TStringBuf::npos && lastColon != TStringBuf::npos)) + { + Host = EndPoint.SubStr(0, lastColon); + Port = EndPoint.SubStr(lastColon + 1, EndPoint.size() - lastColon + 1); + } + + if (endEndPointPos != TStringBuf::npos) { + Service = path.SubStr(endEndPointPos + 1, path.size() - endEndPointPos + 1); + } +} + +ui16 TParsedLocation::GetPort() const { + if (!Port) { + return TStringBuf("https") == Scheme || TStringBuf("fulls") == Scheme || TStringBuf("posts") == Scheme ? 443 : 80; + } + + return FromString<ui16>(Port); +} |