diff options
author | qrort <qrort@yandex-team.com> | 2022-11-30 23:47:12 +0300 |
---|---|---|
committer | qrort <qrort@yandex-team.com> | 2022-11-30 23:47:12 +0300 |
commit | 22f8ae0e3f5d68b92aecccdf96c1d841a0334311 (patch) | |
tree | bffa27765faf54126ad44bcafa89fadecb7a73d7 /library/cpp/http/client/query.cpp | |
parent | 332b99e2173f0425444abb759eebcb2fafaa9209 (diff) | |
download | ydb-22f8ae0e3f5d68b92aecccdf96c1d841a0334311.tar.gz |
validate canons without yatest_common
Diffstat (limited to 'library/cpp/http/client/query.cpp')
-rw-r--r-- | library/cpp/http/client/query.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/library/cpp/http/client/query.cpp b/library/cpp/http/client/query.cpp new file mode 100644 index 0000000000..36a946074b --- /dev/null +++ b/library/cpp/http/client/query.cpp @@ -0,0 +1,92 @@ +#include "query.h" +#include "request.h" + +namespace NHttp { + TFetchQuery::TFetchQuery(const TString& url, + const TFetchOptions& options) + : Url_(url) + , Options_(options) + { + } + + TFetchQuery::TFetchQuery(const TString& url, + const TVector<TString>& headers, + const TFetchOptions& options) + : Url_(url) + , Headers_(headers) + , Options_(options) + { + } + + TFetchQuery::~TFetchQuery() = default; + + TString TFetchQuery::GetUrl() const { + return Url_; + } + + TFetchQuery& TFetchQuery::OnFail(TOnFail cb) { + OnFailCb_ = cb; + return *this; + } + + TFetchQuery& TFetchQuery::OnRedirect(TOnRedirect cb) { + OnRedirectCb_ = cb; + return *this; + } + + TFetchQuery& TFetchQuery::OnPartialRead(NHttpFetcher::TNeedDataCallback cb) { + OnPartialReadCb_ = cb; + return *this; + } + + TFetchRequestRef TFetchQuery::ConstructRequest() const { + TFetchRequestRef request = new TFetchRequest(Url_, Headers_, Options_); + if (OnFailCb_) { + request->SetOnFail(*OnFailCb_); + } + + if (OnRedirectCb_) { + request->SetOnRedirect(*OnRedirectCb_); + } + + if (OnPartialReadCb_) { + request->SetOnPartialRead(*OnPartialReadCb_); + } + + return request; + } + + TFetchState::TFetchState() { + } + + TFetchState::TFetchState(const TFetchRequestRef& req) + : Request_(req) + { + } + + void TFetchState::Cancel() const { + if (Request_) { + Request_->Cancel(); + } + } + + NHttpFetcher::TResultRef TFetchState::Get() const { + if (Request_) { + WaitI(); + return Request_->MakeResult(); + } + return NHttpFetcher::TResultRef(); + } + + void TFetchState::WaitI() const { + WaitT(TDuration::Max()); + } + + bool TFetchState::WaitT(TDuration timeout) const { + if (Request_) { + return Request_->WaitT(timeout); + } + return false; + } + +} |