cesium-native 0.50.0
Loading...
Searching...
No Matches
CurlAssetAccessor.h
1/* <editor-fold desc="MIT License">
2
3Copyright(c) 2023 Timothy Moore
4
5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all
13copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21SOFTWARE.
22
23</editor-fold> */
24
25#pragma once
26
27#include <CesiumAsync/Future.h>
28#include <CesiumAsync/IAssetAccessor.h>
29#include <CesiumAsync/IAssetRequest.h>
30#include <CesiumCurl/Library.h>
31
32#include <cstddef>
33#include <memory>
34#include <span>
35#include <string>
36#include <vector>
37
38namespace CesiumCurl {
39
43struct CESIUMCURL_API CurlAssetAccessorOptions {
47 std::string userAgent{"Mozilla/5.0 Cesium Native CurlAssetAccessor"};
48
55 std::vector<CesiumAsync::IAssetAccessor::THeader> requestHeaders{};
56
64
69 std::string certificatePath{};
70
75 std::string certificateFile{};
76
82 bool doGlobalInit{true};
83};
84
89class CESIUMCURL_API CurlAssetAccessor
90 : public std::enable_shared_from_this<CurlAssetAccessor>,
92public:
99 ~CurlAssetAccessor() override;
100
105
108 get(const CesiumAsync::AsyncSystem& asyncSystem,
109 const std::string& url,
110 const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers)
111 override;
112
115 const CesiumAsync::AsyncSystem& asyncSystem,
116 const std::string& verb,
117 const std::string& url,
118 const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers,
119 const std::span<const std::byte>& contentPayload) override;
120
122 void tick() noexcept override;
123
124private:
125 struct CurlCache;
126 class CurlHandle;
127
128 std::unique_ptr<CurlCache> _pCurlCache;
130};
131
132} // namespace CesiumCurl
A system for managing asynchronous requests and tasks.
Definition AsyncSystem.h:36
A value that will be available in the future, as produced by AsyncSystem.
Definition Future.h:29
Provides asynchronous access to assets, usually files downloaded via HTTP.
An implementation of IAssetAccessor that can make network and local requests to a variety of servers ...
CurlAssetAccessor(const CurlAssetAccessorOptions &options={})
Constructs a new instance.
void tick() noexcept override
CesiumAsync::Future< std::shared_ptr< CesiumAsync::IAssetRequest > > get(const CesiumAsync::AsyncSystem &asyncSystem, const std::string &url, const std::vector< CesiumAsync::IAssetAccessor::THeader > &headers) override
CesiumAsync::Future< std::shared_ptr< CesiumAsync::IAssetRequest > > request(const CesiumAsync::AsyncSystem &asyncSystem, const std::string &verb, const std::string &url, const std::vector< CesiumAsync::IAssetAccessor::THeader > &headers, const std::span< const std::byte > &contentPayload) override
const CurlAssetAccessorOptions & getOptions() const
Gets the options that were used to construct this accessor.
Provides the ability to access HTTP and other network resources using libcurl.
STL namespace.
Options for constructing a CurlAssetAccessor.
bool allowDirectoryCreation
Whether a PUT or POST to a file: URL is allowed to create file system directories to hold the target ...
std::string certificatePath
The path to TLS certificates. If non-empty, this will be provided to libcurl as CURLOPT_CAPATH.
std::string userAgent
The User-Agent header to include with each request.
bool doGlobalInit
Whether to call curl_global_init(CURL_GLOBAL_ALL) at construction time and curl_global_cleanup() at d...
std::string certificateFile
A file containing TLS certificates. If non-empty, this will be provided to libcurl as CURLOPT_CAINFO.
std::vector< CesiumAsync::IAssetAccessor::THeader > requestHeaders
Request headers to automatically include in each request.