cpp-ipfs-http-client
IPFS C++ client library
Loading...
Searching...
No Matches
transport-curl.h
1/* Copyright (c) 2016-2023, The C++ IPFS client library developers
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of
4this software and associated documentation files (the "Software"), to deal in
5the Software without restriction, including without limitation the rights to
6use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7the Software, and to permit persons to whom the Software is furnished to do so,
8subject to the following conditions:
9
10The above copyright notice and this permission notice shall be included in all
11copies or substantial portions of the Software.
12
13THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
19
20#ifndef IPFS_HTTP_TRANSPORT_CURL_H
21#define IPFS_HTTP_TRANSPORT_CURL_H
22
23#include <curl/curl.h>
24#include <ipfs/http/transport.h>
25
26#include <atomic>
27#include <iostream>
28#include <string>
29#include <vector>
30
31namespace ipfs {
32
33namespace http {
34
36class TransportCurl : public Transport {
37 public:
41 bool curlVerbose);
42
46 const TransportCurl& other);
47
51 TransportCurl&& other) noexcept;
52
57 const TransportCurl&);
58
63 TransportCurl&&) noexcept;
64
69 std::unique_ptr<Transport> Clone() const override;
70
73
81 void Fetch(
83 const std::string& url,
85 const std::vector<FileUpload>& files,
87 std::iostream* response) override;
88
96 void StopFetch() override;
97
105 void ResetFetch() override;
106
111 void UrlEncode(
113 const std::string& raw,
115 std::string* encoded) override;
116
119 void Test();
120
121 private:
128 void Perform(
130 const std::string& url,
132 std::iostream* response);
133
135 void InitCurl();
136
138 std::atomic<bool> keep_perform_running_;
139
141 CURLcode global_init_result_;
142
144 CURL* curl_;
145
147 CURLM* multi_handle_;
148
150 bool curl_verbose_;
151
153 bool url_encode_injected_failure = false;
154
156 bool perform_injected_failure = false;
157};
158
159} /* namespace http */
160} /* namespace ipfs */
161
162#endif /* IPFS_HTTP_TRANSPORT_CURL_H */
Convenience class for talking basic HTTP, implemented using CURL.
Definition transport-curl.h:36
~TransportCurl()
Destructor.
Definition transport-curl.cc:161
void ResetFetch() override
Reset the internal state, after StopFetch() is called.
Definition transport-curl.cc:250
void StopFetch() override
Stop the fetch method abruptly, useful whenever the Fetch method is used within a thead,...
Definition transport-curl.cc:248
void Test()
Test the internals that are hard to execute from the public API, like error handling of some exceptio...
Definition transport-curl.cc:372
void Fetch(const std::string &url, const std::vector< FileUpload > &files, std::iostream *response) override
Fetch the contents of a given URL.
Definition transport-curl.cc:170
TransportCurl & operator=(const TransportCurl &)
Copy assignment operator.
Definition transport-curl.cc:133
void UrlEncode(const std::string &raw, std::string *encoded) override
URL encode a string.
Definition transport-curl.cc:252
std::unique_ptr< Transport > Clone() const override
Return a deep copy of this object.
Definition transport-curl.cc:157
Convenience interface for talking basic HTTP.
Definition transport.h:54
IPFS namespace.
Definition client.h:33