diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/messagebus/rain_check/http/client.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/rain_check/http/client.cpp')
-rw-r--r-- | library/cpp/messagebus/rain_check/http/client.cpp | 228 |
1 files changed, 114 insertions, 114 deletions
diff --git a/library/cpp/messagebus/rain_check/http/client.cpp b/library/cpp/messagebus/rain_check/http/client.cpp index 5ef5ceeece..0fb8a93420 100644 --- a/library/cpp/messagebus/rain_check/http/client.cpp +++ b/library/cpp/messagebus/rain_check/http/client.cpp @@ -14,141 +14,141 @@ #include <util/stream/str.h> namespace NRainCheck { - class THttpCallback: public NNeh::IOnRecv { - public: - THttpCallback(NRainCheck::THttpFuture* future) - : Future(future) - { - Y_VERIFY(!!future, "future is NULL"); - } - - void OnRecv(NNeh::THandle& handle) override { - THolder<THttpCallback> self(this); - NNeh::TResponseRef response = handle.Get(); - Future->SetDoneAndSchedule(response); - } - - private: - NRainCheck::THttpFuture* const Future; - }; - - THttpFuture::THttpFuture() - : Task(nullptr) - , ErrorCode(THttpFuture::NoError) + class THttpCallback: public NNeh::IOnRecv { + public: + THttpCallback(NRainCheck::THttpFuture* future) + : Future(future) + { + Y_VERIFY(!!future, "future is NULL"); + } + + void OnRecv(NNeh::THandle& handle) override { + THolder<THttpCallback> self(this); + NNeh::TResponseRef response = handle.Get(); + Future->SetDoneAndSchedule(response); + } + + private: + NRainCheck::THttpFuture* const Future; + }; + + THttpFuture::THttpFuture() + : Task(nullptr) + , ErrorCode(THttpFuture::NoError) { } - THttpFuture::~THttpFuture() { + THttpFuture::~THttpFuture() { } - bool THttpFuture::HasError() const { - return (ErrorCode != THttpFuture::NoError); - } + bool THttpFuture::HasError() const { + return (ErrorCode != THttpFuture::NoError); + } - THttpFuture::EError THttpFuture::GetErrorCode() const { - return ErrorCode; - } + THttpFuture::EError THttpFuture::GetErrorCode() const { + return ErrorCode; + } - TString THttpFuture::GetErrorDescription() const { - return ErrorDescription; - } + TString THttpFuture::GetErrorDescription() const { + return ErrorDescription; + } - THttpClientService::THttpClientService() - : GetProtocol(NNeh::ProtocolFactory()->Protocol("http")) - , FullProtocol(NNeh::ProtocolFactory()->Protocol("full")) - { - Y_VERIFY(!!GetProtocol, "GET protocol is NULL."); - Y_VERIFY(!!FullProtocol, "POST protocol is NULL."); - } + THttpClientService::THttpClientService() + : GetProtocol(NNeh::ProtocolFactory()->Protocol("http")) + , FullProtocol(NNeh::ProtocolFactory()->Protocol("full")) + { + Y_VERIFY(!!GetProtocol, "GET protocol is NULL."); + Y_VERIFY(!!FullProtocol, "POST protocol is NULL."); + } - THttpClientService::~THttpClientService() { - } + THttpClientService::~THttpClientService() { + } - void THttpClientService::SendPost(TString addr, const TString& data, const THttpHeaders& headers, THttpFuture* future) { - Y_VERIFY(!!future, "future is NULL."); + void THttpClientService::SendPost(TString addr, const TString& data, const THttpHeaders& headers, THttpFuture* future) { + Y_VERIFY(!!future, "future is NULL."); - TTaskRunnerBase* current = TTaskRunnerBase::CurrentTask(); - future->SetRunning(current); - future->Task = current; + TTaskRunnerBase* current = TTaskRunnerBase::CurrentTask(); + future->SetRunning(current); + future->Task = current; - THolder<THttpCallback> callback(new THttpCallback(future)); - NNeh::TServiceStatRef stat; - try { + THolder<THttpCallback> callback(new THttpCallback(future)); + NNeh::TServiceStatRef stat; + try { NNeh::TMessage msg(addr.replace(0, NNeh::TParsedLocation(addr).Scheme.size(), "post"), data); - TStringStream headersText; - headers.OutTo(&headersText); - NNeh::NHttp::MakeFullRequest(msg, headersText.Str(), TString()); - FullProtocol->ScheduleRequest(msg, callback.Get(), stat); + TStringStream headersText; + headers.OutTo(&headersText); + NNeh::NHttp::MakeFullRequest(msg, headersText.Str(), TString()); + FullProtocol->ScheduleRequest(msg, callback.Get(), stat); Y_UNUSED(callback.Release()); - } catch (const TNetworkResolutionError& err) { - future->SetFail(THttpFuture::CantResolveNameError, err.AsStrBuf()); - } catch (const yexception& err) { - future->SetFail(THttpFuture::OtherError, err.AsStrBuf()); - } - } - - void THttpClientService::Send(const TString& request, THttpFuture* future) { - Y_VERIFY(!!future, "future is NULL."); - - TTaskRunnerBase* current = TTaskRunnerBase::CurrentTask(); - future->SetRunning(current); - future->Task = current; - - THolder<THttpCallback> callback(new THttpCallback(future)); - NNeh::TServiceStatRef stat; - try { - GetProtocol->ScheduleRequest(NNeh::TMessage::FromString(request), - callback.Get(), - stat); + } catch (const TNetworkResolutionError& err) { + future->SetFail(THttpFuture::CantResolveNameError, err.AsStrBuf()); + } catch (const yexception& err) { + future->SetFail(THttpFuture::OtherError, err.AsStrBuf()); + } + } + + void THttpClientService::Send(const TString& request, THttpFuture* future) { + Y_VERIFY(!!future, "future is NULL."); + + TTaskRunnerBase* current = TTaskRunnerBase::CurrentTask(); + future->SetRunning(current); + future->Task = current; + + THolder<THttpCallback> callback(new THttpCallback(future)); + NNeh::TServiceStatRef stat; + try { + GetProtocol->ScheduleRequest(NNeh::TMessage::FromString(request), + callback.Get(), + stat); Y_UNUSED(callback.Release()); - } catch (const TNetworkResolutionError& err) { - future->SetFail(THttpFuture::CantResolveNameError, err.AsStrBuf()); - } catch (const yexception& err) { - future->SetFail(THttpFuture::OtherError, err.AsStrBuf()); - } - } - - bool THttpFuture::HasHttpCode() const { - return !!HttpCode; - } - - bool THttpFuture::HasResponseBody() const { - return !!Response; + } catch (const TNetworkResolutionError& err) { + future->SetFail(THttpFuture::CantResolveNameError, err.AsStrBuf()); + } catch (const yexception& err) { + future->SetFail(THttpFuture::OtherError, err.AsStrBuf()); + } + } + + bool THttpFuture::HasHttpCode() const { + return !!HttpCode; } - ui32 THttpFuture::GetHttpCode() const { - Y_ASSERT(IsDone()); - Y_ASSERT(HasHttpCode()); + bool THttpFuture::HasResponseBody() const { + return !!Response; + } - return static_cast<ui32>(*HttpCode); - } - - TString THttpFuture::GetResponseBody() const { - Y_ASSERT(IsDone()); - Y_ASSERT(HasResponseBody()); - - return Response->Data; - } + ui32 THttpFuture::GetHttpCode() const { + Y_ASSERT(IsDone()); + Y_ASSERT(HasHttpCode()); - void THttpFuture::SetDoneAndSchedule(TAutoPtr<NNeh::TResponse> response) { - if (!response->IsError()) { - ErrorCode = THttpFuture::NoError; - HttpCode = HttpCodes::HTTP_OK; - } else { - ErrorCode = THttpFuture::BadHttpCodeError; - ErrorDescription = response->GetErrorText(); - - HttpCode = TryGetHttpCodeFromErrorDescription(ErrorDescription); - } - Response.Reset(response); - SetDone(); + return static_cast<ui32>(*HttpCode); } - void THttpFuture::SetFail(THttpFuture::EError errorCode, const TStringBuf& errorDescription) { - ErrorCode = errorCode; - ErrorDescription = errorDescription; - Response.Destroy(); - SetDone(); + TString THttpFuture::GetResponseBody() const { + Y_ASSERT(IsDone()); + Y_ASSERT(HasResponseBody()); + + return Response->Data; + } + + void THttpFuture::SetDoneAndSchedule(TAutoPtr<NNeh::TResponse> response) { + if (!response->IsError()) { + ErrorCode = THttpFuture::NoError; + HttpCode = HttpCodes::HTTP_OK; + } else { + ErrorCode = THttpFuture::BadHttpCodeError; + ErrorDescription = response->GetErrorText(); + + HttpCode = TryGetHttpCodeFromErrorDescription(ErrorDescription); + } + Response.Reset(response); + SetDone(); + } + + void THttpFuture::SetFail(THttpFuture::EError errorCode, const TStringBuf& errorDescription) { + ErrorCode = errorCode; + ErrorDescription = errorDescription; + Response.Destroy(); + SetDone(); } } |