Realm C++ SDK Version v2.2.0

http.hpp

1
2//
3// Copyright 2024 Realm Inc.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
18
19#ifndef CPPREALM_NETWORKING_HTTP_HPP
20#define CPPREALM_NETWORKING_HTTP_HPP
21
22#include <cpprealm/internal/bridge/realm.hpp>
23
24#ifndef REALMCXX_VERSION_MAJOR
25#include <cpprealm/version_numbers.hpp>
26#endif
27
28#include <optional>
29#include <map>
30#include <string>
31
32namespace realm::networking {
33
37 enum class http_method { get, post, patch, put, del };
41 using http_headers = std::map<std::string, std::string>;
42
46 struct request {
50 http_method method = http_method::get;
51
55 std::string url;
56
61 uint64_t timeout_ms = 0;
62
66 http_headers headers;
67
71 std::string body;
72 };
73
77 struct response {
82
87
91 http_headers headers;
92
96 std::string body;
97
101 std::optional<std::int32_t> client_error_code;
102
103 };
104
105 // Interface for providing http transport
107 virtual ~http_transport_client() = default;
108 virtual void send_request_to_server(const request& request,
109 std::function<void(const response&)>&& completion) = 0;
110 };
111
113 std::shared_ptr<http_transport_client> make_http_client();
115 [[maybe_unused]] void set_http_client_factory(std::function<std::shared_ptr<http_transport_client>()>&&);
116
123 std::optional<std::map<std::string, std::string>> custom_http_headers;
127 std::optional<::realm::internal::bridge::realm::sync_config::proxy_config> proxy_config;
128
129 using SSLVerifyCallback = bool(const std::string& server_address,
130 internal::bridge::realm::sync_config::proxy_config::port_type server_port,
131 const char* pem_data, size_t pem_size, int preverify_ok, int depth);
139 std::optional<std::string> ssl_trust_certificate_path;
145 std::function<SSLVerifyCallback> ssl_verify_callback;
146 };
147
148 default_http_transport() = default;
149 default_http_transport(const configuration& c) : m_configuration(c) {}
150
151 ~default_http_transport() = default;
152
153 void send_request_to_server(const ::realm::networking::request& request,
154 std::function<void(const ::realm::networking::response&)>&& completion);
155
156 protected:
157 configuration m_configuration;
158 };
159}
160
161#endif //CPPREALM_NETWORKING_HTTP_HPP
std::optional<::realm::internal::bridge::realm::sync_config::proxy_config > proxy_config
Definition: http.hpp:127
std::optional< std::string > ssl_trust_certificate_path
Definition: http.hpp:139
std::function< SSLVerifyCallback > ssl_verify_callback
Definition: http.hpp:145
std::optional< std::map< std::string, std::string > > custom_http_headers
Definition: http.hpp:123
Built in HTTP transport client.
Definition: http.hpp:118
Definition: http.hpp:46
http_headers headers
Definition: http.hpp:66
std::string body
Definition: http.hpp:71
uint64_t timeout_ms
Definition: http.hpp:61
http_method method
Definition: http.hpp:50
std::string url
Definition: http.hpp:55
Definition: http.hpp:77
std::string body
Definition: http.hpp:96
http_headers headers
Definition: http.hpp:91
std::optional< std::int32_t > client_error_code
Definition: http.hpp:101
int custom_status_code
Definition: http.hpp:86
int http_status_code
Definition: http.hpp:81