userver: /data/code/userver/libraries/s3api/src/s3api/s3_connection.hpp Source File
Loading...
Searching...
No Matches
s3_connection.hpp
1#pragma once
2
3#include <optional>
4#include <string>
5
6#include <userver/clients/http/request.hpp>
7#include <userver/clients/http/response.hpp>
8#include <userver/utils/str_icase.hpp>
9
10#include <userver/s3api/clients/s3api.hpp>
11#include <userver/s3api/models/fwd.hpp>
12#include <userver/s3api/models/s3api_connection_type.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace clients::http {
17class Client;
18}
19
20namespace s3api {
21
22// Represents a connection to s3 api
23// includes an url to the api and a http interface
25public:
26 S3Connection(
27 clients::http::Client& http_client,
28 S3ConnectionType connection_type,
29 std::string server_url,
30 const ConnectionCfg& params
31 )
32 : api_url_(std::move(server_url)),
33 connection_type_(connection_type),
34 http_client_(http_client),
35 config_(params) {}
36
37 S3Connection(const S3Connection& other) = default;
38
39 ~S3Connection() = default;
40
41 std::shared_ptr<clients::http::Response> RequestApi(Request& r, std::string_view method_name);
42
43 std::shared_ptr<clients::http::Response> DoStartApiRequest(const Request& r) const;
44
45 std::shared_ptr<clients::http::Response> StartApiRequest(const Request& r) const;
46
47 std::string GetHost() const { return api_url_; }
48
49 void UpdateConfig(ConnectionCfg&& config) { config_ = config; }
50
51private:
52 std::string GetUrl(const Request& r, S3ConnectionType connection_type) const;
53
54 ConnectionCfg GetConfig() const { return config_; }
55
56 const std::string api_url_;
57 S3ConnectionType connection_type_;
58 clients::http::Client& http_client_;
59 ConnectionCfg config_;
60};
61
62std::shared_ptr<S3Connection> MakeS3Connection(
63 clients::http::Client& http_client,
64 S3ConnectionType connection_type,
65 std::string server_url,
66 const ConnectionCfg& params
67);
68
69} // namespace s3api
70
71USERVER_NAMESPACE_END