aboutsummaryrefslogtreecommitdiffstats
path: root/yt
diff options
context:
space:
mode:
authorbarykinni <barykinni@yandex-team.com>2024-08-01 11:45:50 +0300
committerbarykinni <barykinni@yandex-team.com>2024-08-01 11:56:43 +0300
commit3ac0db172a3dd434aa6f776d71efd11de9f46bba (patch)
tree20536fc7a746751680b8591f6f3e29ef5c7bb746 /yt
parent226ad6e44ddaecc763a95f179974da04b9c9fa83 (diff)
downloadydb-3ac0db172a3dd434aa6f776d71efd11de9f46bba.tar.gz
CHYT-1167: add request method to http client
746dc5319b081f1c1c324129e799a0f17605b084
Diffstat (limited to 'yt')
-rw-r--r--yt/yt/core/http/client.cpp22
-rw-r--r--yt/yt/core/http/client.h8
-rw-r--r--yt/yt/core/http/mock/client.cpp6
-rw-r--r--yt/yt/core/http/mock/client.h3
-rw-r--r--yt/yt/core/http/stream.cpp2
-rw-r--r--yt/yt/core/https/client.cpp9
6 files changed, 38 insertions, 12 deletions
diff --git a/yt/yt/core/http/client.cpp b/yt/yt/core/http/client.cpp
index 6214168bd1..dc7bf3077d 100644
--- a/yt/yt/core/http/client.cpp
+++ b/yt/yt/core/http/client.cpp
@@ -94,6 +94,17 @@ public:
return StartRequest(EMethod::Put, url, headers);
}
+ TFuture<IResponsePtr> Request(
+ EMethod method,
+ const TString& url,
+ const std::optional<TSharedRef>& body,
+ const THeadersPtr& headers) override
+ {
+ return WrapError(url, BIND([=, this, this_ = MakeStrong(this)] {
+ return DoRequest(method, url, body, headers);
+ }));
+ }
+
private:
const TClientConfigPtr Config_;
const IDialerPtr Dialer_;
@@ -294,17 +305,6 @@ private:
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/client.h b/yt/yt/core/http/client.h
index 0f6ba0239f..a75df31142 100644
--- a/yt/yt/core/http/client.h
+++ b/yt/yt/core/http/client.h
@@ -2,6 +2,8 @@
#include "public.h"
+#include "yt/yt/core/http/http.h"
+
#include <yt/yt/core/concurrency/public.h>
#include <yt/yt/core/net/public.h>
@@ -63,6 +65,12 @@ struct IClient
virtual TFuture<IActiveRequestPtr> StartPut(
const TString& url,
const THeadersPtr& headers = nullptr) = 0;
+
+ virtual TFuture<IResponsePtr> Request(
+ EMethod method,
+ const TString& url,
+ const std::optional<TSharedRef>& body,
+ const THeadersPtr& headers) = 0;
};
DEFINE_REFCOUNTED_TYPE(IClient)
diff --git a/yt/yt/core/http/mock/client.cpp b/yt/yt/core/http/mock/client.cpp
index bec6691be0..69f0b345c0 100644
--- a/yt/yt/core/http/mock/client.cpp
+++ b/yt/yt/core/http/mock/client.cpp
@@ -110,6 +110,12 @@ TFuture<IActiveRequestPtr> TMockClient::StartPut(const TString& /*url*/, const T
YT_UNIMPLEMENTED();
}
+TFuture<IResponsePtr> TMockClient::Request(EMethod method, const TString& url, const std::optional<TSharedRef>& body, const THeadersPtr& headers)
+{
+ auto mockResponse = Request(method, url, ToString(body), DumpHeadersSafe(headers));
+ return MakeFuture<IResponsePtr>(New<TMockResponseStream>(mockResponse));
+}
+
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NHttp
diff --git a/yt/yt/core/http/mock/client.h b/yt/yt/core/http/mock/client.h
index ea93320e2c..61a01e9999 100644
--- a/yt/yt/core/http/mock/client.h
+++ b/yt/yt/core/http/mock/client.h
@@ -32,11 +32,14 @@ public:
TFuture<IActiveRequestPtr> StartPatch(const TString& url, const THeadersPtr& headers) override;
TFuture<IActiveRequestPtr> StartPut(const TString& url, const THeadersPtr& headers) override;
+ TFuture<IResponsePtr> Request(EMethod method, const TString& url, const std::optional<TSharedRef>& body, const THeadersPtr& headers) override;
+
MOCK_METHOD(TMockResponse, Get, (const TString& url, const TMockHeaders& headers));
MOCK_METHOD(TMockResponse, Post, (const TString& url, const TString& body, const TMockHeaders& headers));
MOCK_METHOD(TMockResponse, Patch, (const TString& url, const TString& body, const TMockHeaders& headers));
MOCK_METHOD(TMockResponse, Put, (const TString& url, const TString& body, const TMockHeaders& headers));
MOCK_METHOD(TMockResponse, Delete, (const TString& url, const TMockHeaders& headers));
+ MOCK_METHOD(TMockResponse, Request, (EMethod method, const TString& url, const std::optional<TString>& body, const TMockHeaders& headers));
};
DECLARE_REFCOUNTED_CLASS(TMockClient)
diff --git a/yt/yt/core/http/stream.cpp b/yt/yt/core/http/stream.cpp
index 2811da6eae..db16ffdf53 100644
--- a/yt/yt/core/http/stream.cpp
+++ b/yt/yt/core/http/stream.cpp
@@ -682,7 +682,7 @@ TSharedRef THttpOutput::GetHeadersPart(std::optional<size_t> contentLength)
if (contentLength) {
if (MessageType_ == EMessageType::Response ||
- (MessageType_ == EMessageType::Request && methodNeedsContentLength)) {
+ (MessageType_ == EMessageType::Request && (*contentLength > 0 || methodNeedsContentLength))) {
messageHeaders << "Content-Length: " << *contentLength << "\r\n";
}
} else {
diff --git a/yt/yt/core/https/client.cpp b/yt/yt/core/https/client.cpp
index 95ac66b856..7d5fbc70e5 100644
--- a/yt/yt/core/https/client.cpp
+++ b/yt/yt/core/https/client.cpp
@@ -89,6 +89,15 @@ public:
return Underlying_->StartPut(url, headers);
}
+ TFuture<IResponsePtr> Request(
+ EMethod method,
+ const TString& url,
+ const std::optional<TSharedRef>& body,
+ const THeadersPtr& headers) override
+ {
+ return Underlying_->Request(method, url, body, headers);
+ }
+
private:
const IClientPtr Underlying_;
};