diff options
author | msherbakov <msherbakov@yandex-team.ru> | 2022-02-10 16:49:16 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:16 +0300 |
commit | c224a621661ddd69699f9476922eb316607ef57e (patch) | |
tree | 33f4d878aa0a9faa964005e06bfab0272313aa71 /library/cpp/monlib/service/format.h | |
parent | 29d0b2eeae154d04156e0698067c0c21a97ea61d (diff) | |
download | ydb-c224a621661ddd69699f9476922eb316607ef57e.tar.gz |
Restoring authorship annotation for <msherbakov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/monlib/service/format.h')
-rw-r--r-- | library/cpp/monlib/service/format.h | 148 |
1 files changed, 74 insertions, 74 deletions
diff --git a/library/cpp/monlib/service/format.h b/library/cpp/monlib/service/format.h index 0044b586b1..d004f73bf1 100644 --- a/library/cpp/monlib/service/format.h +++ b/library/cpp/monlib/service/format.h @@ -1,86 +1,86 @@ -#pragma once - +#pragma once + #include <library/cpp/monlib/encode/format.h> - -#include <util/string/ascii.h> -#include <util/generic/yexception.h> -#include <util/generic/typetraits.h> - -namespace NMonitoring { - namespace NPrivate { - Y_HAS_MEMBER(Name, Name); - Y_HAS_MEMBER(second, Second); - } // namespace NPrivate - - template <typename TRequest> - ECompression ParseCompression(const TRequest& req) { - auto&& headers = req.GetHeaders(); - - constexpr auto isPlainPair = NPrivate::THasSecond<std::decay_t<decltype(*headers.begin())>>::value; - - auto it = FindIf(std::begin(headers), std::end(headers), + +#include <util/string/ascii.h> +#include <util/generic/yexception.h> +#include <util/generic/typetraits.h> + +namespace NMonitoring { + namespace NPrivate { + Y_HAS_MEMBER(Name, Name); + Y_HAS_MEMBER(second, Second); + } // namespace NPrivate + + template <typename TRequest> + ECompression ParseCompression(const TRequest& req) { + auto&& headers = req.GetHeaders(); + + constexpr auto isPlainPair = NPrivate::THasSecond<std::decay_t<decltype(*headers.begin())>>::value; + + auto it = FindIf(std::begin(headers), std::end(headers), [=] (const auto& h) { - if constexpr (NPrivate::THasName<std::decay_t<decltype(h)>>::value) { + if constexpr (NPrivate::THasName<std::decay_t<decltype(h)>>::value) { return AsciiCompareIgnoreCase(h.Name(), TStringBuf("accept-encoding")) == 0; - } else if (isPlainPair) { + } else if (isPlainPair) { return AsciiCompareIgnoreCase(h.first, TStringBuf("accept-encoding")) == 0; - } - }); - - if (it == std::end(headers)) { - return NMonitoring::ECompression::IDENTITY; - } - - NMonitoring::ECompression val{}; - if constexpr (isPlainPair) { - val = CompressionFromAcceptEncodingHeader(it->second); - } else { - val = CompressionFromAcceptEncodingHeader(it->Value()); - } - - return val != NMonitoring::ECompression::UNKNOWN - ? val - : NMonitoring::ECompression::IDENTITY; - } - - template <typename TRequest> - NMonitoring::EFormat ParseFormat(const TRequest& req) { - auto&& formatStr = req.GetParams() + } + }); + + if (it == std::end(headers)) { + return NMonitoring::ECompression::IDENTITY; + } + + NMonitoring::ECompression val{}; + if constexpr (isPlainPair) { + val = CompressionFromAcceptEncodingHeader(it->second); + } else { + val = CompressionFromAcceptEncodingHeader(it->Value()); + } + + return val != NMonitoring::ECompression::UNKNOWN + ? val + : NMonitoring::ECompression::IDENTITY; + } + + template <typename TRequest> + NMonitoring::EFormat ParseFormat(const TRequest& req) { + auto&& formatStr = req.GetParams() .Get(TStringBuf("format")); - + if (!formatStr.empty()) { if (formatStr == TStringBuf("SPACK")) { - return EFormat::SPACK; + return EFormat::SPACK; } else if (formatStr == TStringBuf("TEXT")) { - return EFormat::TEXT; + return EFormat::TEXT; } else if (formatStr == TStringBuf("JSON")) { - return EFormat::JSON; - } else { - ythrow yexception() << "unknown format: " << formatStr << ". Only spack is supported here"; - } - } - - auto&& headers = req.GetHeaders(); - constexpr auto isPlainPair = NPrivate::THasSecond<std::decay_t<decltype(*headers.begin())>>::value; - - auto it = FindIf(std::begin(headers), std::end(headers), + return EFormat::JSON; + } else { + ythrow yexception() << "unknown format: " << formatStr << ". Only spack is supported here"; + } + } + + auto&& headers = req.GetHeaders(); + constexpr auto isPlainPair = NPrivate::THasSecond<std::decay_t<decltype(*headers.begin())>>::value; + + auto it = FindIf(std::begin(headers), std::end(headers), [=] (const auto& h) { - if constexpr (NPrivate::THasName<std::decay_t<decltype(h)>>::value) { + if constexpr (NPrivate::THasName<std::decay_t<decltype(h)>>::value) { return AsciiCompareIgnoreCase(h.Name(), TStringBuf("accept")) == 0; - } else if (isPlainPair) { + } else if (isPlainPair) { return AsciiCompareIgnoreCase(h.first, TStringBuf("accept")) == 0; - } - }); - - if (it != std::end(headers)) { - if constexpr (isPlainPair) { - return FormatFromAcceptHeader(it->second); - } else { - return FormatFromAcceptHeader(it->Value()); - } - } - - return EFormat::UNKNOWN; - } - -} // namespace NMonitoring + } + }); + + if (it != std::end(headers)) { + if constexpr (isPlainPair) { + return FormatFromAcceptHeader(it->second); + } else { + return FormatFromAcceptHeader(it->Value()); + } + } + + return EFormat::UNKNOWN; + } + +} // namespace NMonitoring |