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/fetch/fetch_request.cpp | |
parent | 332b99e2173f0425444abb759eebcb2fafaa9209 (diff) | |
download | ydb-22f8ae0e3f5d68b92aecccdf96c1d841a0334311.tar.gz |
validate canons without yatest_common
Diffstat (limited to 'library/cpp/http/client/fetch/fetch_request.cpp')
-rw-r--r-- | library/cpp/http/client/fetch/fetch_request.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/library/cpp/http/client/fetch/fetch_request.cpp b/library/cpp/http/client/fetch/fetch_request.cpp new file mode 100644 index 0000000000..2f8453fc45 --- /dev/null +++ b/library/cpp/http/client/fetch/fetch_request.cpp @@ -0,0 +1,114 @@ +#include "fetch_request.h" + +#include <library/cpp/deprecated/atomic/atomic.h> + +// TRequest +namespace NHttpFetcher { + const TString DEFAULT_ACCEPT_ENCODING = "gzip, deflate"; + const size_t DEFAULT_MAX_HEADER_SIZE = 100 << 10; + const size_t DEFAULT_MAX_BODY_SIZE = 1 << 29; + + TRequest::TRequest(const TString& url, TCallBack onFetch) + : Url(url) + , Deadline(TInstant::Now() + DEFAULT_REQUEST_TIMEOUT) + , Freshness(DEFAULT_REQUEST_FRESHNESS) + , Priority(40) + , IgnoreRobotsTxt(false) + , LangRegion(ELR_RU) + , OnFetch(onFetch) + , AcceptEncoding(DEFAULT_ACCEPT_ENCODING) + , OnlyHeaders(false) + , MaxHeaderSize(DEFAULT_MAX_HEADER_SIZE) + , MaxBodySize(DEFAULT_MAX_BODY_SIZE) + { + GenerateSequence(); + } + + TRequest::TRequest(const TString& url, bool ignoreRobotsTxt, TDuration timeout, TDuration freshness, TCallBack onFetch) + : Url(url) + , Deadline(Now() + timeout) + , Freshness(freshness) + , Priority(40) + , IgnoreRobotsTxt(ignoreRobotsTxt) + , LangRegion(ELR_RU) + , OnFetch(onFetch) + , AcceptEncoding(DEFAULT_ACCEPT_ENCODING) + , OnlyHeaders(false) + , MaxHeaderSize(DEFAULT_MAX_HEADER_SIZE) + , MaxBodySize(DEFAULT_MAX_BODY_SIZE) + { + GenerateSequence(); + } + + TRequest::TRequest(const TString& url, TDuration timeout, TDuration freshness, bool ignoreRobots, + size_t priority, const TMaybe<TString>& login, const TMaybe<TString>& password, + ELangRegion langRegion, TCallBack onFetch) + : Url(url) + , Deadline(Now() + timeout) + , Freshness(freshness) + , Priority(priority) + , Login(login) + , Password(password) + , IgnoreRobotsTxt(ignoreRobots) + , LangRegion(langRegion) + , OnFetch(onFetch) + , AcceptEncoding(DEFAULT_ACCEPT_ENCODING) + , OnlyHeaders(false) + , MaxHeaderSize(DEFAULT_MAX_HEADER_SIZE) + , MaxBodySize(DEFAULT_MAX_BODY_SIZE) + { + GenerateSequence(); + } + + void TRequest::GenerateSequence() { + static TAtomic nextSeq = 0; + Sequence = AtomicIncrement(nextSeq); + } + + TRequestRef TRequest::Clone() { + THolder<TRequest> request = THolder<TRequest>(new TRequest(*this)); + request->GenerateSequence(); + return request.Release(); + } + + void TRequest::Dump(IOutputStream& out) { + out << "url: " << Url << "\n"; + out << "timeout: " << (Deadline - Now()).MilliSeconds() << " ms\n"; + out << "freshness: " << Freshness.Seconds() << "\n"; + out << "priority: " << Priority << "\n"; + if (!!Login) { + out << "login: " << *Login << "\n"; + } + if (!!Password) { + out << "password: " << *Password << "\n"; + } + if (!!OAuthToken) { + out << "oauth token: " << *OAuthToken << "\n"; + } + if (IgnoreRobotsTxt) { + out << "ignore robots: " << IgnoreRobotsTxt << "\n"; + } + out << "lang reg: " << LangRegion2Str(LangRegion) << "\n"; + if (!!CustomHost) { + out << "custom host: " << *CustomHost << "\n"; + } + if (!!UserAgent) { + out << "user agent: " << *UserAgent << "\n"; + } + if (!!AcceptEncoding) { + out << "accept enc: " << *AcceptEncoding << "\n"; + } + if (OnlyHeaders) { + out << "only headers: " << OnlyHeaders << "\n"; + } + out << "max header sz: " << MaxHeaderSize << "\n"; + out << "max body sz: " << MaxBodySize << "\n"; + if (!!PostData) { + out << "post data: " << *PostData << "\n"; + } + if (!!ContentType) { + out << "content type: " << *ContentType << "\n"; + } + } + +} |