#pragma once #include #include #include #include namespace NMonitoring { namespace NPrivate { Y_HAS_MEMBER(Name, Name); Y_HAS_MEMBER(second, Second); } // namespace NPrivate template ECompression ParseCompression(const TRequest& req) { auto&& headers = req.GetHeaders(); constexpr auto isPlainPair = NPrivate::THasSecond>::value; auto it = FindIf(std::begin(headers), std::end(headers), [=] (const auto& h) { if constexpr (NPrivate::THasName>::value) { return AsciiEqualsIgnoreCase(h.Name(), TStringBuf("accept-encoding")); } else if constexpr (isPlainPair) { return AsciiEqualsIgnoreCase(h.first, TStringBuf("accept-encoding")); } else { static_assert(TDependentFalse); } }); 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 NMonitoring::EFormat ParseFormat(const TRequest& req) { auto&& formatStr = req.GetParams() .Get(TStringBuf("format")); if (!formatStr.empty()) { if (formatStr == TStringBuf("SPACK")) { return EFormat::SPACK; } else if (formatStr == TStringBuf("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>::value; auto it = FindIf(std::begin(headers), std::end(headers), [=] (const auto& h) { if constexpr (NPrivate::THasName>::value) { return AsciiEqualsIgnoreCase(h.Name(), TStringBuf("accept")); } else if constexpr (isPlainPair) { return AsciiEqualsIgnoreCase(h.first, TStringBuf("accept")); } else { static_assert(TDependentFalse); } }); if (it != std::end(headers)) { if constexpr (isPlainPair) { return FormatFromAcceptHeader(it->second); } else { return FormatFromAcceptHeader(it->Value()); } } return EFormat::UNKNOWN; } } // namespace NMonitoring