diff options
author | trofimenkov <trofimenkov@yandex-team.com> | 2024-05-29 11:24:03 +0300 |
---|---|---|
committer | trofimenkov <trofimenkov@yandex-team.com> | 2024-05-29 11:41:02 +0300 |
commit | 9314042511cd9d2598ed16eb0a19c84909895938 (patch) | |
tree | 29a96bee879eef2cff2bb1fbf98f50e080f0622c /library/cpp/http/simple/http_client.cpp | |
parent | 8788a47c2b48e19d7246346fae2ae5e446575a7a (diff) | |
download | ydb-9314042511cd9d2598ed16eb0a19c84909895938.tar.gz |
MaxRedirectCount param for http/simple
1b80d64b6a03772edc52f2331a860ff0b5621898
Diffstat (limited to 'library/cpp/http/simple/http_client.cpp')
-rw-r--r-- | library/cpp/http/simple/http_client.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/library/cpp/http/simple/http_client.cpp b/library/cpp/http/simple/http_client.cpp index 818dc048ad..342236f9a3 100644 --- a/library/cpp/http/simple/http_client.cpp +++ b/library/cpp/http/simple/http_client.cpp @@ -301,8 +301,14 @@ TKeepAliveHttpClient TSimpleHttpClient::CreateClient() const { void TSimpleHttpClient::PrepareClient(TKeepAliveHttpClient&) const { } +TRedirectableHttpClient::TRedirectableHttpClient(const TOptions& options) + : TSimpleHttpClient(options) + , Opts(options) +{ +} + TRedirectableHttpClient::TRedirectableHttpClient(const TString& host, ui32 port, TDuration socketTimeout, TDuration connectTimeout) - : TSimpleHttpClient(host, port, socketTimeout, connectTimeout) + : TRedirectableHttpClient(TOptions().Host(host).Port(port).SocketTimeout(socketTimeout).ConnectTimeout(connectTimeout)) { } @@ -315,6 +321,10 @@ void TRedirectableHttpClient::PrepareClient(TKeepAliveHttpClient& cl) const { void TRedirectableHttpClient::ProcessResponse(const TStringBuf relativeUrl, THttpInput& input, IOutputStream* output, const unsigned statusCode) const { for (auto i = input.Headers().Begin(), e = input.Headers().End(); i != e; ++i) { if (0 == TString::compare(i->Name(), TStringBuf("Location"))) { + if (Opts.MaxRedirectCount() == 0) { + ythrow THttpRequestException(statusCode) << "Exceeds MaxRedirectCount limit, code " << statusCode << " at " << Host << relativeUrl; + } + TVector<TString> request_url_parts, request_body_parts; size_t splitted_index = 0; @@ -339,7 +349,12 @@ void TRedirectableHttpClient::ProcessResponse(const TStringBuf relativeUrl, THtt } } - TRedirectableHttpClient cl(url, port, TDuration::Seconds(60), TDuration::Seconds(60)); + auto opts = Opts; + opts.Host(url); + opts.Port(port); + opts.MaxRedirectCount(opts.MaxRedirectCount() - 1); + + TRedirectableHttpClient cl(opts); if (HttpsVerification) { cl.EnableVerificationForHttps(); } |