diff options
author | Alexey Efimov <xeno@prnwatch.com> | 2022-02-10 16:49:42 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:42 +0300 |
commit | 0fd1998e1b2369f50fb694556f817d3c7fef10c8 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/monlib | |
parent | 26e0e4fb5e5cd6b4d7f4c21f9fcd7978891bf946 (diff) | |
download | ydb-0fd1998e1b2369f50fb694556f817d3c7fef10c8.tar.gz |
Restoring authorship annotation for Alexey Efimov <xeno@prnwatch.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/monlib')
-rw-r--r-- | library/cpp/monlib/service/mon_service_http_request.cpp | 74 | ||||
-rw-r--r-- | library/cpp/monlib/service/mon_service_http_request.h | 6 | ||||
-rw-r--r-- | library/cpp/monlib/service/monservice.cpp | 16 | ||||
-rw-r--r-- | library/cpp/monlib/service/monservice.h | 20 | ||||
-rw-r--r-- | library/cpp/monlib/service/pages/index_mon_page.cpp | 22 | ||||
-rw-r--r-- | library/cpp/monlib/service/pages/index_mon_page.h | 2 | ||||
-rw-r--r-- | library/cpp/monlib/service/pages/templates.h | 28 | ||||
-rw-r--r-- | library/cpp/monlib/service/service.cpp | 70 | ||||
-rw-r--r-- | library/cpp/monlib/service/service.h | 6 |
9 files changed, 122 insertions, 122 deletions
diff --git a/library/cpp/monlib/service/mon_service_http_request.cpp b/library/cpp/monlib/service/mon_service_http_request.cpp index b22e53d370..5d805631d9 100644 --- a/library/cpp/monlib/service/mon_service_http_request.cpp +++ b/library/cpp/monlib/service/mon_service_http_request.cpp @@ -42,44 +42,44 @@ const TCgiParameters& TMonService2HttpRequest::GetPostParams() const { } TStringBuf TMonService2HttpRequest::GetHeader(TStringBuf name) const { - const THttpHeaders& headers = HttpRequest->GetHeaders(); - const THttpInputHeader* header = headers.FindHeader(name); - if (header != nullptr) { - return header->Value(); - } - return TStringBuf(); -} - + const THttpHeaders& headers = HttpRequest->GetHeaders(); + const THttpInputHeader* header = headers.FindHeader(name); + if (header != nullptr) { + return header->Value(); + } + return TStringBuf(); +} + const THttpHeaders& TMonService2HttpRequest::GetHeaders() const { return HttpRequest->GetHeaders(); } - -TString TMonService2HttpRequest::GetRemoteAddr() const { - return HttpRequest->GetRemoteAddr(); -} - + +TString TMonService2HttpRequest::GetRemoteAddr() const { + return HttpRequest->GetRemoteAddr(); +} + TStringBuf TMonService2HttpRequest::GetCookie(TStringBuf name) const { - TStringBuf cookie = GetHeader("Cookie"); - size_t size = cookie.size(); - size_t start = 0; - while (start < size) { - size_t semicolon = cookie.find(';', start); - auto pair = cookie.substr(start, semicolon - start); - if (!pair.empty()) { - size_t equal = pair.find('='); - if (equal != TStringBuf::npos) { - auto cookieName = pair.substr(0, equal); - if (cookieName == name) { - size_t valueStart = equal + 1; - auto cookieValue = pair.substr(valueStart, semicolon - valueStart); - return cookieValue; - } - } - start = semicolon; - while (start < size && (cookie[start] == ' ' || cookie[start] == ';')) { - ++start; - } - } - } - return TStringBuf(); -} + TStringBuf cookie = GetHeader("Cookie"); + size_t size = cookie.size(); + size_t start = 0; + while (start < size) { + size_t semicolon = cookie.find(';', start); + auto pair = cookie.substr(start, semicolon - start); + if (!pair.empty()) { + size_t equal = pair.find('='); + if (equal != TStringBuf::npos) { + auto cookieName = pair.substr(0, equal); + if (cookieName == name) { + size_t valueStart = equal + 1; + auto cookieValue = pair.substr(valueStart, semicolon - valueStart); + return cookieValue; + } + } + start = semicolon; + while (start < size && (cookie[start] == ' ' || cookie[start] == ';')) { + ++start; + } + } + } + return TStringBuf(); +} diff --git a/library/cpp/monlib/service/mon_service_http_request.h b/library/cpp/monlib/service/mon_service_http_request.h index d46e2bcd31..b4f2f8f0c5 100644 --- a/library/cpp/monlib/service/mon_service_http_request.h +++ b/library/cpp/monlib/service/mon_service_http_request.h @@ -24,7 +24,7 @@ namespace NMonitoring { virtual const THttpHeaders& GetHeaders() const = 0; virtual TStringBuf GetHeader(TStringBuf name) const = 0; virtual TStringBuf GetCookie(TStringBuf name) const = 0; - virtual TString GetRemoteAddr() const = 0; + virtual TString GetRemoteAddr() const = 0; virtual TString GetServiceTitle() const = 0; @@ -71,8 +71,8 @@ namespace NMonitoring { TStringBuf GetHeader(TStringBuf name) const override; TStringBuf GetCookie(TStringBuf name) const override; const THttpHeaders& GetHeaders() const override; - TString GetRemoteAddr() const override; - + TString GetRemoteAddr() const override; + IMonPage* GetPage() const override { return MonPage; } diff --git a/library/cpp/monlib/service/monservice.cpp b/library/cpp/monlib/service/monservice.cpp index b45ba2c19b..d1b9cda1d2 100644 --- a/library/cpp/monlib/service/monservice.cpp +++ b/library/cpp/monlib/service/monservice.cpp @@ -41,14 +41,14 @@ TMonService2::TMonService2(const THttpServerOptions& options, TSimpleSharedPtr<I TMonService2::TMonService2(ui16 port, ui32 threads, const TString& title, THolder<IAuthProvider> auth) : TMonService2(port, TString(), threads, title, std::move(auth)) -{ -} - +{ +} + TMonService2::TMonService2(ui16 port, const TString& title, THolder<IAuthProvider> auth) : TMonService2(port, TString(), 0, title, std::move(auth)) { } - + void TMonService2::OutputIndex(IOutputStream& out) { IndexMonPage->OutputIndex(out, true); } @@ -123,7 +123,7 @@ IMonPage* TMonService2::FindPage(const TString& relativePath) { TIndexMonPage* TMonService2::FindIndexPage(const TString& relativePath) { return IndexMonPage->FindIndexPage(relativePath); } - -void TMonService2::SortPages() { - IndexMonPage->SortPages(); -} + +void TMonService2::SortPages() { + IndexMonPage->SortPages(); +} diff --git a/library/cpp/monlib/service/monservice.h b/library/cpp/monlib/service/monservice.h index 7a6c0383eb..8f5e52fcdb 100644 --- a/library/cpp/monlib/service/monservice.h +++ b/library/cpp/monlib/service/monservice.h @@ -20,23 +20,23 @@ namespace NMonitoring { THolder<IAuthProvider> AuthProvider_; public: - static THttpServerOptions HttpServerOptions(ui16 port, const TString& host, ui32 threads) { + static THttpServerOptions HttpServerOptions(ui16 port, const TString& host, ui32 threads) { THttpServerOptions opts(port); - if (!host.empty()) { - opts.SetHost(host); - } + if (!host.empty()) { + opts.SetHost(host); + } opts.SetClientTimeout(TDuration::Minutes(1)); opts.EnableCompression(true); opts.SetThreads(threads); - opts.SetMaxConnections(std::max<ui32>(100, threads)); - opts.EnableRejectExcessConnections(true); + opts.SetMaxConnections(std::max<ui32>(100, threads)); + opts.EnableRejectExcessConnections(true); return opts; } - static THttpServerOptions HttpServerOptions(ui16 port, ui32 threads) { - return HttpServerOptions(port, TString(), threads); - } - + static THttpServerOptions HttpServerOptions(ui16 port, ui32 threads) { + return HttpServerOptions(port, TString(), threads); + } + public: explicit TMonService2(ui16 port, const TString& title = GetProgramName(), THolder<IAuthProvider> auth = nullptr); explicit TMonService2(ui16 port, ui32 threads, const TString& title = GetProgramName(), THolder<IAuthProvider> auth = nullptr); diff --git a/library/cpp/monlib/service/pages/index_mon_page.cpp b/library/cpp/monlib/service/pages/index_mon_page.cpp index 461cd30698..83ff8b529a 100644 --- a/library/cpp/monlib/service/pages/index_mon_page.cpp +++ b/library/cpp/monlib/service/pages/index_mon_page.cpp @@ -136,16 +136,16 @@ void TIndexMonPage::OutputBody(IMonHttpRequest& req) { out << "<div>\n" << "</body>\n"; } - + void TIndexMonPage::SortPages() { - TGuard<TMutex> g(Mtx); - std::sort(Pages.begin(), Pages.end(), [](const TMonPagePtr& a, const TMonPagePtr& b) { + TGuard<TMutex> g(Mtx); + std::sort(Pages.begin(), Pages.end(), [](const TMonPagePtr& a, const TMonPagePtr& b) { return AsciiCompareIgnoreCase(a->GetTitle(), b->GetTitle()) < 0; - }); -} - -void TIndexMonPage::ClearPages() { - TGuard<TMutex> g(Mtx); - Pages.clear(); - PagesByPath.clear(); -} + }); +} + +void TIndexMonPage::ClearPages() { + TGuard<TMutex> g(Mtx); + Pages.clear(); + PagesByPath.clear(); +} diff --git a/library/cpp/monlib/service/pages/index_mon_page.h b/library/cpp/monlib/service/pages/index_mon_page.h index ea4df882ad..bf514a3105 100644 --- a/library/cpp/monlib/service/pages/index_mon_page.h +++ b/library/cpp/monlib/service/pages/index_mon_page.h @@ -32,7 +32,7 @@ namespace NMonitoring { TIndexMonPage* FindIndexPage(const TString& relativePath); void SortPages(); - void ClearPages(); + void ClearPages(); }; } diff --git a/library/cpp/monlib/service/pages/templates.h b/library/cpp/monlib/service/pages/templates.h index 6a48a9229e..b4656f059f 100644 --- a/library/cpp/monlib/service/pages/templates.h +++ b/library/cpp/monlib/service/pages/templates.h @@ -123,32 +123,32 @@ namespace NMonitoring { { Str << "<" << tag; - if (!cls.empty()) { + if (!cls.empty()) { Str << " class=\"" << cls << "\""; } - if (!for0.empty()) { + if (!for0.empty()) { Str << " for=\"" << for0 << "\""; } - if (!id.empty()) { + if (!id.empty()) { Str << "id=\"" << id << "\""; } Str << ">"; } TTag(IOutputStream& str, std::initializer_list<std::pair<TStringBuf, TStringBuf>> attributes) - : Str(str) - { - Str << "<" << tag; - for (const std::pair<TStringBuf, TStringBuf>& attr : attributes) { - if (!attr.second.empty()) { - Str << ' ' << attr.first << "=\"" << attr.second << "\""; - } - } - Str << ">"; - } - + : Str(str) + { + Str << "<" << tag; + for (const std::pair<TStringBuf, TStringBuf>& attr : attributes) { + if (!attr.second.empty()) { + Str << ' ' << attr.first << "=\"" << attr.second << "\""; + } + } + Str << ">"; + } + ~TTag() { try { Str << "</" << tag << ">"; diff --git a/library/cpp/monlib/service/service.cpp b/library/cpp/monlib/service/service.cpp index 0a87d8dff4..929efbf816 100644 --- a/library/cpp/monlib/service/service.cpp +++ b/library/cpp/monlib/service/service.cpp @@ -15,10 +15,10 @@ namespace NMonitoring { class THttpClient: public IHttpRequest { public: - void ServeRequest(THttpInput& in, IOutputStream& out, const NAddr::IRemoteAddr* remoteAddr, const THandler& Handler) { + void ServeRequest(THttpInput& in, IOutputStream& out, const NAddr::IRemoteAddr* remoteAddr, const THandler& Handler) { try { try { - RemoteAddr = remoteAddr; + RemoteAddr = remoteAddr; THttpHeaderParser parser; parser.Init(&Header); if (parser.Execute(in.FirstLine().data(), in.FirstLine().size()) < 0) { @@ -34,15 +34,15 @@ namespace NMonitoring { out << "HTTP/1.1 400 Bad request\r\nConnection: Close\r\n\r\n"; return; } - Headers = &in.Headers(); + Headers = &in.Headers(); CgiParams.Scan(Url.Get(THttpURL::FieldQuery)); } catch (...) { out << "HTTP/1.1 500 Internal server error\r\nConnection: Close\r\n\r\n"; YSYSLOG(TLOG_ERR, "THttpClient: internal error while serving monitoring request: %s", CurrentExceptionMessage().data()); } - if (Header.http_method == HTTP_METHOD_POST) - TransferData(&in, &PostContent); + if (Header.http_method == HTTP_METHOD_POST) + TransferData(&in, &PostContent); Handler(out, *this); out.Finish(); @@ -64,49 +64,49 @@ namespace NMonitoring { return CgiParams; } const TCgiParameters& GetPostParams() const override { - if (PostParams.empty() && !PostContent.Buffer().Empty()) - const_cast<THttpClient*>(this)->ScanPostParams(); + if (PostParams.empty() && !PostContent.Buffer().Empty()) + const_cast<THttpClient*>(this)->ScanPostParams(); return PostParams; } - TStringBuf GetPostContent() const override { - return TStringBuf(PostContent.Buffer().Data(), PostContent.Buffer().Size()); - } + TStringBuf GetPostContent() const override { + return TStringBuf(PostContent.Buffer().Data(), PostContent.Buffer().Size()); + } HTTP_METHOD GetMethod() const override { return (HTTP_METHOD)Header.http_method; } - void ScanPostParams() { + void ScanPostParams() { PostParams.Scan(TStringBuf(PostContent.Buffer().data(), PostContent.Buffer().size())); - } - - const THttpHeaders& GetHeaders() const override { - if (Headers != nullptr) { - return *Headers; - } - static THttpHeaders defaultHeaders; - return defaultHeaders; - } - - TString GetRemoteAddr() const override { - return RemoteAddr ? NAddr::PrintHostAndPort(*RemoteAddr) : TString(); - } - + } + + const THttpHeaders& GetHeaders() const override { + if (Headers != nullptr) { + return *Headers; + } + static THttpHeaders defaultHeaders; + return defaultHeaders; + } + + TString GetRemoteAddr() const override { + return RemoteAddr ? NAddr::PrintHostAndPort(*RemoteAddr) : TString(); + } + private: THttpRequestHeader Header; - const THttpHeaders* Headers = nullptr; + const THttpHeaders* Headers = nullptr; THttpURL Url; TCgiParameters CgiParams; TCgiParameters PostParams; - TBufferOutput PostContent; - const NAddr::IRemoteAddr* RemoteAddr = nullptr; + TBufferOutput PostContent; + const NAddr::IRemoteAddr* RemoteAddr = nullptr; }; /* TCoHttpServer */ class TCoHttpServer::TConnection: public THttpClient { public: - TConnection(const TCoHttpServer::TAcceptFull& acc, const TCoHttpServer& parent) - : Socket(acc.S->Release()) - , RemoteAddr(acc.Remote) + TConnection(const TCoHttpServer::TAcceptFull& acc, const TCoHttpServer& parent) + : Socket(acc.S->Release()) + , RemoteAddr(acc.Remote) , Parent(parent) { } @@ -119,7 +119,7 @@ namespace NMonitoring { THttpOutput out(&io, &in); // buffer reply so there will be ne context switching TStringStream s; - ServeRequest(in, s, RemoteAddr, Parent.Handler); + ServeRequest(in, s, RemoteAddr, Parent.Handler); out << s.Str(); out.Finish(); } catch (...) { @@ -129,7 +129,7 @@ namespace NMonitoring { private: TSocketHolder Socket; - const NAddr::IRemoteAddr* RemoteAddr; + const NAddr::IRemoteAddr* RemoteAddr; const TCoHttpServer& Parent; }; @@ -156,7 +156,7 @@ namespace NMonitoring { } void TCoHttpServer::OnAcceptFull(const TAcceptFull& acc) { - THolder<TConnection> conn(new TConnection(acc, *this)); + THolder<TConnection> conn(new TConnection(acc, *this)); Executor.Create(*conn, "client"); Y_UNUSED(conn.Release()); } @@ -195,7 +195,7 @@ namespace NMonitoring { } bool Reply(void*) override { - ServeRequest(Input(), Output(), NAddr::GetPeerAddr(Socket()).Get(), Parent.Handler); + ServeRequest(Input(), Output(), NAddr::GetPeerAddr(Socket()).Get(), Parent.Handler); return true; } diff --git a/library/cpp/monlib/service/service.h b/library/cpp/monlib/service/service.h index 0a10cf2a3d..2f66dddaf8 100644 --- a/library/cpp/monlib/service/service.h +++ b/library/cpp/monlib/service/service.h @@ -21,10 +21,10 @@ namespace NMonitoring { virtual const char* GetPath() const = 0; virtual const TCgiParameters& GetParams() const = 0; virtual const TCgiParameters& GetPostParams() const = 0; - virtual TStringBuf GetPostContent() const = 0; + virtual TStringBuf GetPostContent() const = 0; virtual HTTP_METHOD GetMethod() const = 0; - virtual const THttpHeaders& GetHeaders() const = 0; - virtual TString GetRemoteAddr() const = 0; + virtual const THttpHeaders& GetHeaders() const = 0; + virtual TString GetRemoteAddr() const = 0; }; // first param - output stream to write result to // second param - URL of request |