5#include <unordered_map>
7#include <userver/http/common_headers.hpp>
8#include <userver/http/url.hpp>
10USERVER_NAMESPACE_BEGIN
12namespace s3api::api_methods {
15 std::string_view bucket,
16 std::string_view path,
18 std::string_view content_type,
19 const std::optional<std::string_view>& content_disposition
26 req.headers[USERVER_NAMESPACE::
http::
headers::kContentLength] = std::to_string(data.size());
27 req.headers[USERVER_NAMESPACE::http::headers::kContentType] = content_type;
29 if (content_disposition.has_value()) {
30 req.headers[USERVER_NAMESPACE::http::headers::kContentDisposition] = *content_disposition;
33 req.body = std::move(data);
37Request DeleteObject(std::string_view bucket, std::string_view path) {
39 req.method = clients::http::
HttpMethod::kDelete;
45Request GetObject(std::string_view bucket, std::string_view path, std::optional<std::string_view> version) {
52 req.req +=
"?" + USERVER_NAMESPACE::http::MakeQuery({{
"versionId", *version}});
58Request GetObjectHead(std::string_view bucket, std::string_view path) {
66void SetRange(
Request& req, size_t begin, size_t end) {
67 req.headers[USERVER_NAMESPACE::http::headers::kRange] =
68 "bytes=" + std::to_string(begin) +
'-' + std::to_string(end);
71void SetRange(
Request& req, std::string_view range) { req.headers[USERVER_NAMESPACE::http::headers::kRange] = range; }
73Request GetBuckets() {
return Request{{},
"",
"",
"", clients::http::
HttpMethod::kGet}; }
76 std::string_view bucket,
77 std::string_view path,
79 std::string_view marker,
80 std::string_view delimiter
86 std::unordered_map<std::string, std::string> params;
87 params.emplace(
"prefix", path);
89 params.emplace(
"max-keys", std::to_string(max_keys));
92 if (!marker.empty()) {
93 params.emplace(
"marker", marker);
96 if (!delimiter.empty()) {
97 params.emplace(
"delimiter", delimiter);
100 req.req =
"?" + USERVER_NAMESPACE::http::MakeQuery(params);
104 std::string_view source_bucket,
105 std::string_view source_key,
106 std::string_view dest_bucket,
107 std::string_view dest_key,
108 std::string_view content_type
112 req.bucket = dest_bucket;
115 req.headers[headers::kAmzCopySource] = fmt::format(
"/{}/{}", source_bucket, source_key);
116 req.headers[USERVER_NAMESPACE::http::headers::kContentType] = content_type;