Ocean
Loading...
Searching...
No Matches
HTTPSClient.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef FACEBOOK_NETWORK_HTTPS_CLIENT_H
9#define FACEBOOK_NETWORK_HTTPS_CLIENT_H
10
12#include "ocean/network/Port.h"
13
14#include "ocean/base/Callback.h"
15
16namespace Ocean
17{
18
19namespace Network
20{
21
22/**
23 * This class implements a HTTPS Client supporting GET and POST requests.
24 * @ingroup network
25 */
26class OCEAN_NETWORK_EXPORT HTTPSClient
27{
28 public:
29
30 /**
31 * Definition of a vector holding characters.
32 */
33 using Buffer = std::vector<uint8_t>;
34
35 /**
36 * Callback for receiving progress information when performing a HTTP request.
37 * The first parameter represents how many Bytes of the payload have been received so far, with range [0, infinity)
38 * The second parameter represents the total size of the payload in bytes, with range [0, infinity). If the total size is unknown this parameter is 0.
39 */
41
42 protected:
43
44 /**
45 * Forward declaration.
46 */
47 class CurlSessionData;
48
49 public:
50
51 /**
52 * Function to executes a HTTPS GET (site/file download) request.
53 * @param url The URL of the HTTPS site which is requested, beginning with "HTTPS://"
54 * @param data The resulting request data
55 * @param port The port of the HTTPS server
56 * @param timeout The timeout this function waits for the server's response, with range (0, infinity)
57 * @param abort Optional flag that may be set to True by another thread to abort the request
58 * @param progressCallback Optional callback for receiving progress information
59 * @param caCertificates Optional path to a file containing a list of trusted CA certificates, in PEM format; otherwise, the default trusted CA certificates will be used
60 * @return True, if succeeded
61 */
62 static bool httpsGetRequest(const std::string& url, Buffer& data, const Port& port = Port(443, Port::TYPE_READABLE), const double timeout = 5.0, bool* abort = nullptr, const ProgressCallback& progressCallback = ProgressCallback(), const std::string& caCertificates = std::string());
63
64 /**
65 * Function to executes a HTTPS POST (site/file upload) request.
66 * @param url The URL of the HTTPS site which is requested, beginning with "HTTPS://"
67 * @param requestData The buffer of the request data
68 * @param requestDataSize The number of bytes of the request data
69 * @param data The resulting response data
70 * @param port The port of the HTTPS server
71 * @param timeout The timeout this function waits for the server's response, with range (0, infinity)
72 * @param additionalHeaders Optional additional HTTP headers
73 * @param caCertificates Optional path to a file containing a list of trusted CA certificates, in PEM format; otherwise, the default trusted CA certificates will be used
74 * @return True, if succeeded
75 */
76 static bool httpsPostRequest(const std::string& url, const uint8_t* requestData, const size_t requestDataSize, Buffer& data, const Port& port = Port(443, Port::TYPE_READABLE), const double timeout = 5.0, const Strings& additionalHeaders = Strings(), const std::string& caCertificates = std::string());
77
78 /**
79 * Converts a URL to a URI.
80 * @param url The URL to convert, e.g., 'https://www.website.com/index.html"
81 * @param protocol The resulting protocol, will be 'https' if successful
82 * @param host The resulting host without ending '/'
83 * @param uri The resulting URI, can be empty if the URL does not include an URI
84 * @return True, if succeeded
85 */
86 static bool url2uri(const std::string& url, std::string& protocol, std::string& host, std::string& uri);
87
88 protected:
89
90#if defined(__APPLE__)
91
92 /**
93 * Function to executes a HTTPS GET (site/file download) request (specialized function for Apple platforms).
94 * @sa httpsGetRequest()
95 * @param url The URL of the HTTPS site which is requested, beginning with "HTTPS://"
96 * @param data The resulting request data
97 * @param port The port of the HTTPS server
98 * @param timeout The timeout this function waits for the server's response, with range (0, infinity)
99 * @param abort Optional flag that may be set to True by another thread to abort the request
100 * @param progressCallback Optional callback for receiving progress information
101 * @return True, if succeeded
102 */
103 static bool httpsGetRequestApple(const std::string& url, Buffer& data, const Port& port, const double timeout, bool* abort, const ProgressCallback& progressCallback);
104
105 /**
106 * Function to executes a HTTPS POST (site/file upload) request (specialized function for Apple platforms).
107 * @sa httpsPostRequest()
108 * @param url The URL of the HTTPS site which is requested, beginning with "HTTPS://"
109 * @param requestData The buffer of the request data
110 * @param requestDataSize The number of bytes of the request data
111 * @param data The resulting response data
112 * @param port The port of the HTTPS server
113 * @param timeout The timeout this function waits for the server's response, with range (0, infinity)
114 * @param additionalHeaders Optional additional HTTP headers
115 * @return True, if succeeded
116 */
117 static bool httpsPostRequestApple(const std::string& url, const uint8_t* requestData, const size_t requestDataSize, Buffer& data, const Port& port, const double timeout, const Strings& additionalHeaders);
118
119#endif // defined(__APPLE__)
120
121};
122
123}
124
125}
126
127#endif // FACEBOOK_NETWORK_HTTPS_CLIENT_H
This class implements a container for callback functions.
Definition Callback.h:3454
This class implements a HTTPS Client supporting GET and POST requests.
Definition HTTPSClient.h:27
static bool url2uri(const std::string &url, std::string &protocol, std::string &host, std::string &uri)
Converts a URL to a URI.
static bool httpsPostRequest(const std::string &url, const uint8_t *requestData, const size_t requestDataSize, Buffer &data, const Port &port=Port(443, Port::TYPE_READABLE), const double timeout=5.0, const Strings &additionalHeaders=Strings(), const std::string &caCertificates=std::string())
Function to executes a HTTPS POST (site/file upload) request.
std::vector< uint8_t > Buffer
Definition of a vector holding characters.
Definition HTTPSClient.h:33
static bool httpsGetRequest(const std::string &url, Buffer &data, const Port &port=Port(443, Port::TYPE_READABLE), const double timeout=5.0, bool *abort=nullptr, const ProgressCallback &progressCallback=ProgressCallback(), const std::string &caCertificates=std::string())
Function to executes a HTTPS GET (site/file download) request.
static bool httpsPostRequestApple(const std::string &url, const uint8_t *requestData, const size_t requestDataSize, Buffer &data, const Port &port, const double timeout, const Strings &additionalHeaders)
Function to executes a HTTPS POST (site/file upload) request (specialized function for Apple platform...
static bool httpsGetRequestApple(const std::string &url, Buffer &data, const Port &port, const double timeout, bool *abort, const ProgressCallback &progressCallback)
Function to executes a HTTPS GET (site/file download) request (specialized function for Apple platfor...
This class wraps a port number with 16 bits.
Definition Port.h:26
std::vector< std::string > Strings
Definition of a vector holding strings.
Definition Base.h:162
The namespace covering the entire Ocean framework.
Definition Accessor.h:15