diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-03-01 12:07:15 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-03-01 12:47:27 +0300 |
commit | 3d5a72449da534180a0275ec11ca62afb218bd74 (patch) | |
tree | fb84903ea6c2b96f76d5d2d483080772180bc12f | |
parent | 8d8b376242e30239752ee26ad7b2305b3557dc01 (diff) | |
download | ydb-3d5a72449da534180a0275ec11ca62afb218bd74.tar.gz |
Intermediate changes
-rw-r--r-- | build/mapping.conf.json | 10 | ||||
-rw-r--r-- | yt/yt/core/http/client.cpp | 41 | ||||
-rw-r--r-- | yt/yt/core/http/config.cpp | 3 | ||||
-rw-r--r-- | yt/yt/core/http/config.h | 2 | ||||
-rw-r--r-- | yt/yt/core/http/stream.cpp | 19 | ||||
-rw-r--r-- | yt/yt/core/http/stream.h | 4 |
6 files changed, 65 insertions, 14 deletions
diff --git a/build/mapping.conf.json b/build/mapping.conf.json index a3d1eaabbc..c62fbcef46 100644 --- a/build/mapping.conf.json +++ b/build/mapping.conf.json @@ -220,14 +220,19 @@ "1277521710": "https://devtools-registry.s3.yandex.net/1277521710", "5776380974": "https://devtools-registry.s3.yandex.net/5776380974", "5777101734": "https://devtools-registry.s3.yandex.net/5777101734", + "5909068951": "https://devtools-registry.s3.yandex.net/5909068951", "5776379446": "https://devtools-registry.s3.yandex.net/5776379446", "5777100597": "https://devtools-registry.s3.yandex.net/5777100597", + "5909067709": "https://devtools-registry.s3.yandex.net/5909067709", "5776375952": "https://devtools-registry.s3.yandex.net/5776375952", "5777098178": "https://devtools-registry.s3.yandex.net/5777098178", + "5909065014": "https://devtools-registry.s3.yandex.net/5909065014", "5776374505": "https://devtools-registry.s3.yandex.net/5776374505", "5777096988": "https://devtools-registry.s3.yandex.net/5777096988", + "5909063641": "https://devtools-registry.s3.yandex.net/5909063641", "5776377955": "https://devtools-registry.s3.yandex.net/5776377955", "5777099502": "https://devtools-registry.s3.yandex.net/5777099502", + "5909066324": "https://devtools-registry.s3.yandex.net/5909066324", "3167009386": "https://devtools-registry.s3.yandex.net/3167009386", "3050798466": "https://devtools-registry.s3.yandex.net/3050798466", "3064614561": "https://devtools-registry.s3.yandex.net/3064614561", @@ -528,14 +533,19 @@ "1277521710": "infra/kernel/tools/atop/build/atop-static.tar.gz", "5776380974": "none-none-none-result_resources/jdk-darwin-aarch64.yandex.tgz", "5777101734": "none-none-none-result_resources/jdk-darwin-aarch64.yandex.tgz", + "5909068951": "none-none-none-result_resources/jdk-darwin-aarch64.yandex.tgz", "5776379446": "none-none-none-result_resources/jdk-darwin-x86_64.yandex.tgz", "5777100597": "none-none-none-result_resources/jdk-darwin-x86_64.yandex.tgz", + "5909067709": "none-none-none-result_resources/jdk-darwin-x86_64.yandex.tgz", "5776375952": "none-none-none-result_resources/jdk-linux-aarch64.yandex.tgz", "5777098178": "none-none-none-result_resources/jdk-linux-aarch64.yandex.tgz", + "5909065014": "none-none-none-result_resources/jdk-linux-aarch64.yandex.tgz", "5776374505": "none-none-none-result_resources/jdk-linux-x86_64.yandex.tgz", "5777096988": "none-none-none-result_resources/jdk-linux-x86_64.yandex.tgz", + "5909063641": "none-none-none-result_resources/jdk-linux-x86_64.yandex.tgz", "5776377955": "none-none-none-result_resources/jdk-windows-amd64.yandex.tgz", "5777099502": "none-none-none-result_resources/jdk-windows-amd64.yandex.tgz", + "5909066324": "none-none-none-result_resources/jdk-windows-amd64.yandex.tgz", "3167009386": "openjdk 11.0.15 vanilla for darwin", "3050798466": "openjdk 11.0.15 vanilla for darwin-arm64", "3064614561": "openjdk 11.0.15 vanilla for linux", diff --git a/yt/yt/core/http/client.cpp b/yt/yt/core/http/client.cpp index b6eb5181be..f133c10291 100644 --- a/yt/yt/core/http/client.cpp +++ b/yt/yt/core/http/client.cpp @@ -270,27 +270,40 @@ private: })); } - TFuture<IResponsePtr> Request( + IResponsePtr DoRequest( EMethod method, const TString& url, const std::optional<TSharedRef>& body, - const THeadersPtr& headers) + const THeadersPtr& headers, + int redirectCount = 0) { - return WrapError(url, BIND([=, this, this_ = MakeStrong(this)] { - auto [request, response] = StartAndWriteHeaders(method, url, headers); + auto [request, response] = StartAndWriteHeaders(method, url, headers); - if (body) { - WaitFor(request->WriteBody(*body)) - .ThrowOnError(); - } else { - WaitFor(request->Close()) - .ThrowOnError(); - } + if (body) { + WaitFor(request->WriteBody(*body)) + .ThrowOnError(); + } else { + WaitFor(request->Close()) + .ThrowOnError(); + } - // Waits for response headers internally. - response->GetStatusCode(); + // Waits for response headers internally. + auto redirectUrl = response->TryGetRedirectUrl(); + if (redirectUrl && redirectCount < Config_->MaxRedirectCount) { + return DoRequest(method, *redirectUrl, body, headers, redirectCount + 1); + } - return IResponsePtr(response); + return IResponsePtr(response); + } + + TFuture<IResponsePtr> Request( + EMethod method, + const TString& url, + const std::optional<TSharedRef>& body, + const THeadersPtr& headers) + { + return WrapError(url, BIND([=, this, this_ = MakeStrong(this)] { + return DoRequest(method, url, body, headers); })); } }; diff --git a/yt/yt/core/http/config.cpp b/yt/yt/core/http/config.cpp index 0497c15327..2ef4635792 100644 --- a/yt/yt/core/http/config.cpp +++ b/yt/yt/core/http/config.cpp @@ -11,6 +11,9 @@ void THttpIOConfig::Register(TRegistrar registrar) registrar.Parameter("read_buffer_size", &TThis::ReadBufferSize) .Default(128_KB); + registrar.Parameter("max_redirect_count", &TThis::MaxRedirectCount) + .Default(0); + registrar.Parameter("connection_idle_timeout", &TThis::ConnectionIdleTimeout) .Default(TDuration::Minutes(5)); diff --git a/yt/yt/core/http/config.h b/yt/yt/core/http/config.h index 937f99a29a..65d297d473 100644 --- a/yt/yt/core/http/config.h +++ b/yt/yt/core/http/config.h @@ -16,6 +16,8 @@ class THttpIOConfig public: int ReadBufferSize; + int MaxRedirectCount; + TDuration ConnectionIdleTimeout; TDuration HeaderReadTimeout; diff --git a/yt/yt/core/http/stream.cpp b/yt/yt/core/http/stream.cpp index 4820919f1f..485903b194 100644 --- a/yt/yt/core/http/stream.cpp +++ b/yt/yt/core/http/stream.cpp @@ -523,6 +523,25 @@ void THttpInput::MaybeLogSlowProgress() } } +bool THttpInput::IsRedirectCode(EStatusCode code) const +{ + return code == EStatusCode::MovedPermanently || code == EStatusCode::Found || + code == EStatusCode::SeeOther || code == EStatusCode::UseProxy || + code == EStatusCode::TemporaryRedirect || code == EStatusCode::PermanentRedirect; +} + +std::optional<TString> THttpInput::TryGetRedirectUrl() +{ + EnsureHeadersReceived(); + if (IsRedirectCode(GetStatusCode())) { + auto url = Headers_->Find("Location"); + if (url) { + return *url; + } + } + return std::nullopt; +} + //////////////////////////////////////////////////////////////////////////////// THttpOutput::THttpOutput( diff --git a/yt/yt/core/http/stream.h b/yt/yt/core/http/stream.h index 44783c1013..b01da702f1 100644 --- a/yt/yt/core/http/stream.h +++ b/yt/yt/core/http/stream.h @@ -129,6 +129,8 @@ public: int GetPort() const override; void SetPort(int port); + std::optional<TString> TryGetRedirectUrl(); + private: const NNet::IConnectionPtr Connection_; const NNet::TNetworkAddress RemoteAddress_; @@ -166,6 +168,8 @@ private: TSharedRef DoRead(); void MaybeLogSlowProgress(); + + bool IsRedirectCode(EStatusCode code) const; }; DEFINE_REFCOUNTED_TYPE(THttpInput) |