Skip to content

Commit 84ac613

Browse files
authored
Modified API documentation for HTTP (#796)
Reviewed and modified the API documentation for HTTP, added missing documentation. Relates-To: OLPEDGE-1445 Signed-off-by: Halyna Dumych <ext-halyna.dumych@here.com>
1 parent 9a2387a commit 84ac613

File tree

9 files changed

+335
-228
lines changed

9 files changed

+335
-228
lines changed

olp-cpp-sdk-core/include/olp/core/http/HttpStatusCode.h

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ namespace olp {
2626
namespace http {
2727

2828
/**
29-
* @brief HTTP status codes as specified by RFC7231.
30-
* For more information see
31-
* https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
29+
* @brief HTTP status codes, as specified in RFC7231.
30+
*
31+
* For more information, see the [Hypertext Transfer Protocol (HTTP) Status Code
32+
* Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml).
3233
*/
3334
class CORE_API HttpStatusCode {
3435
public:
@@ -110,14 +111,18 @@ class CORE_API HttpStatusCode {
110111
};
111112

112113
/**
113-
* @brief Check if the given error code is temporary error.
114-
* Some errors are sever or due to wrong user data an thus cannot be repeated,
115-
* respectively will always result in the same error.
116-
* @param[in] http_code A HTTP status code or a \c olp::http::ErrorCode.
117-
* @return \c true in case request can be repeated, \c false otherwise.
114+
* @brief Checks if the given error code is a temporary error.
115+
*
116+
* Some errors are sever errors or caused by wrong user data.
117+
* These errors cannot be repeated and always result in the same error.
118+
*
119+
* @param[in] http_code The HTTP status code or `olp::http::ErrorCode`.
120+
*
121+
* @return True if the request can be repeated; false otherwise.
118122
*/
119123
static bool IsRetryable(int http_code) {
120-
if (http_code < 0) return false;
124+
if (http_code < 0)
125+
return false;
121126

122127
switch (http_code) {
123128
case HttpStatusCode::INTERNAL_SERVER_ERROR:
@@ -137,10 +142,12 @@ class CORE_API HttpStatusCode {
137142
}
138143

139144
/**
140-
* @brief Maps \c olp::http::ErrorCode or HTTP status code to a
141-
* \c olp::client::ErrorCode.
142-
* @param[in] http_code A HTTP status code or a \c olp::http::ErrorCode.
143-
* @return The coresponding \c olp::client::ErrorCode.
145+
* @brief Maps an HTTP status code or `olp::http::ErrorCode` to
146+
* `olp::client::ErrorCode`.
147+
*
148+
* @param[in] http_code The HTTP status code or `olp::http::ErrorCode`.
149+
*
150+
* @return The corresponding `olp::client::ErrorCode`.
144151
*/
145152
static olp::client::ErrorCode GetErrorCode(int http_code) {
146153
// ErrorCode (negative numbers)
@@ -166,7 +173,7 @@ class CORE_API HttpStatusCode {
166173
}
167174
}
168175

169-
// HttpStatusCode
176+
// `HttpStatusCode`
170177
switch (http_code) {
171178
case HttpStatusCode::BAD_REQUEST:
172179
return olp::client::ErrorCode::BadRequest;

olp-cpp-sdk-core/include/olp/core/http/Network.h

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,76 +29,79 @@
2929
#include <olp/core/http/NetworkTypes.h>
3030

3131
namespace olp {
32-
/// The HTTP namespace provides a platform specific network abstraction layer.
32+
/// Provides a platform specific network abstraction layer.
3333
namespace http {
3434

3535
/**
36-
* @brief The Network class represents HTTP client abstraction.
36+
* @brief An HTTP client abstraction.
3737
*/
3838
class CORE_API Network {
3939
public:
40-
/// Callback to be called when the request has been processed or cancelled.
40+
/// The callback that is called when the request is processed or canceled.
4141
using Callback = std::function<void(NetworkResponse response)>;
4242

43-
/// Callback to be called when a header has been received.
43+
/// The callback that is called when a header is received.
4444
using HeaderCallback =
4545
std::function<void(std::string key, std::string value)>;
4646

47-
/// Callback to be called when a chunk of data has been received.
47+
/// The callback that is called when a chunk of data is received.
4848
using DataCallback = std::function<void(
4949
const std::uint8_t* data, std::uint64_t offset, std::size_t length)>;
5050

51-
/// Represents the request and response payload type
51+
/// The request and response payload type.
5252
using Payload = std::shared_ptr<std::ostream>;
5353

5454
/**
55-
* @brief The Statistics structure represents the network statistics for a
56-
* specific bucket.
55+
* @brief Network statistics for a specific bucket.
5756
*/
5857
struct Statistics {
59-
/// The total bytes downloaded including size of headers and payload.
58+
/// The total bytes downloaded, including the size of headers and payload.
6059
uint64_t bytes_downloaded{0ull};
61-
/// The total bytes uploaded including size of headers and payload.
60+
/// The total bytes uploaded, including the size of headers and payload.
6261
uint64_t bytes_uploaded{0ull};
6362
/// The total number of requests made by network.
6463
uint32_t total_requests{0u};
65-
/// The total number of requests failed.
64+
/// The total number of requests that failed.
6665
uint32_t total_failed{0u};
6766
};
6867

6968
virtual ~Network() = default;
7069

7170
/**
72-
* @brief Send network request.
73-
* @param[in] request Request to be sent.
74-
* @param[in] payload Stream to store response payload data.
75-
* @param[in] callback Callback to be called when request is fully processed
76-
* or cancelled. After this call there will be no more callbacks triggered and
77-
* users can consider the request as done.
78-
* @param[in] header_callback Callback to be called when a HTTP header has
79-
* been received. Each HTTP header entry will result in a callback.
80-
* @param[in] data_callback Callback to be called when a chunk of data is
81-
* received. This callback can be triggered multiple times all prior to the
82-
* final Callback call.
83-
* @return SendOutcome which represent either a valid \c RequestId as the
84-
* unique request identifier or a \c ErrorCode in case of failure. In case of
85-
* failure no callbacks will be triggered.
71+
* @brief Sends the network request.
72+
*
73+
* @param[in] request The request that is sent.
74+
* @param[in] payload The stream used to store the response payload data.
75+
* @param[in] callback The callback that is called when the request is fully
76+
* processed or canceled. After this call, no more callbacks are triggered,
77+
* and you can consider the request as done.
78+
* @param[in] header_callback The callback that is called when an HTTP header
79+
* is received. Each HTTP header entry results in a callback.
80+
* @param[in] data_callback The callback that is called when a chunk of data
81+
* is received. You can trigger triggered multiple times before the final
82+
* `Callback` call.
83+
*
84+
* @return `SendOutcome` that represent either a valid `RequestId` as
85+
* the unique request identifier or an `ErrorCode` in case of failure.
86+
* In case of failure, no callbacks are triggered.
8687
*/
8788
virtual SendOutcome Send(NetworkRequest request, Payload payload,
8889
Callback callback,
8990
HeaderCallback header_callback = nullptr,
9091
DataCallback data_callback = nullptr) = 0;
9192

9293
/**
93-
* @brief Cancel request by RequestId.
94-
* Once the request was cancelled the user will receive a final Callback with
95-
* an appropriate NetworkResponse marked as cancelled.
96-
* @param[in] id The unique RequestId of the request to be cancelled.
94+
* @brief Cancels the request using `RequestId`.
95+
*
96+
* When the request is canceled, the user receives a final `Callback` with
97+
* an appropriate `NetworkResponse` marked as canceled.
98+
*
99+
* @param[in] id The unique ID of the request that you want to cancel.
97100
*/
98101
virtual void Cancel(RequestId id) = 0;
99102

100103
/**
101-
* @brief Sets default network headers.
104+
* @brief Sets the default network headers.
102105
*
103106
* Default headers are applied to each request passed to the `Send` method.
104107
* User agents are concatenated.
@@ -108,26 +111,27 @@ class CORE_API Network {
108111
virtual void SetDefaultHeaders(Headers headers);
109112

110113
/**
111-
* @brief Set the current statistics bucket.
114+
* @brief Sets the current bucket statistics.
112115
*
113116
* @param[in] bucked_id The bucket ID.
114117
*/
115118
virtual void SetCurrentBucket(uint8_t bucket_id);
116119

117120
/**
118-
* @brief Get the statistics for a bucket.
121+
* @brief Gets the statistics for a bucket.
119122
*
120-
* By default, this returns the statistics for the default bucket, with the ID 0.
123+
* By default, it returns the statistics for the default bucket and the ID
124+
* that equals 0.
121125
*
122126
* @param[in] bucked_id The bucket ID.
123127
*
124-
* @return Statistics which contains the statistic for the requested bucket.
128+
* @return The statistic for the requested bucket.
125129
*/
126130
virtual Statistics GetStatistics(uint8_t bucket_id = 0);
127131
};
128132

129133
/**
130-
* @brief Create default Network implementation.
134+
* @brief Creates a default `Network` implementation.
131135
*/
132136
CORE_API std::shared_ptr<Network> CreateDefaultNetwork(
133137
size_t max_requests_count);

olp-cpp-sdk-core/include/olp/core/http/NetworkConstants.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ namespace olp {
2626
namespace http {
2727

2828
/**
29-
* HTTP Headers
29+
* @brief The HTTP headers.
3030
*/
3131
static constexpr auto kAuthorizationHeader = "Authorization";
3232
static constexpr auto kContentTypeHeader = "Content-Type";
3333
static constexpr auto kUserAgentHeader = "User-Agent";
3434

3535
/**
36-
* Custom constants
36+
* @brief The custom constants.
3737
*/
3838
static constexpr auto kBearer = "Bearer";
3939
static constexpr auto kOlpSdkUserAgent =

olp-cpp-sdk-core/include/olp/core/http/NetworkProxySettings.h

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,96 +28,111 @@ namespace olp {
2828
namespace http {
2929

3030
/**
31-
* @brief This class contains proxy configuration for the network interface to
32-
* be applied per request.
31+
* @brief Contains a proxy configuration for the network interface that
32+
* is applied per request.
3333
*/
3434
class CORE_API NetworkProxySettings final {
3535
public:
3636
/// The proxy type.
3737
enum class Type {
38-
NONE, ///< Don't use proxy.
39-
HTTP, ///< HTTP proxy as in https://www.ietf.org/rfc/rfc2068.txt.
40-
SOCKS4, ///< SOCKS4 proxy.
41-
SOCKS4A, ///< SOCKS4a Proxy. Proxy resolves URL hostname.
42-
SOCKS5, ///< SOCKS5 proxy.
43-
SOCKS5_HOSTNAME, ///< SOCKS5 Proxy. Proxy resolves URL hostname.
38+
NONE, ///< Don't use the proxy.
39+
HTTP, ///< HTTP proxy as in https://www.ietf.org/rfc/rfc2068.txt
40+
SOCKS4, ///< SOCKS4 proxy.
41+
SOCKS4A, ///< SOCKS4a proxy. Proxy resolves the URL hostname.
42+
SOCKS5, ///< SOCKS5 proxy.
43+
SOCKS5_HOSTNAME, ///< SOCKS5 Proxy. Proxy resolves the URL hostname.
4444
};
4545

4646
/**
47-
* @brief Get proxy type.
48-
* @return proxy type.
47+
* @brief Gets the proxy type.
48+
*
49+
* @return The proxy type.
4950
*/
5051
Type GetType() const;
5152

5253
/**
53-
* @brief Set proxy type.
54-
* @param[in] type Proxy type.
55-
* @return reference to *this.
54+
* @brief Sets the proxy type.
55+
*
56+
* @param[in] type The proxy type.
57+
*
58+
* @return A reference to *this.
5659
*/
5760
NetworkProxySettings& WithType(Type type);
5861

5962
/**
60-
* @brief Get proxy hostname.
61-
* @return proxy hostname.
63+
* @brief Gets the proxy hostname.
64+
*
65+
* @return The proxy hostname.
6266
*/
6367
const std::string& GetHostname() const;
6468

6569
/**
66-
* Set proxy hostname.
67-
* @param[in] hostname Proxy hostname.
68-
* @return reference to *this.
70+
* @brief Sets the proxy hostname.
71+
*
72+
* @param[in] hostname The proxy hostname.
73+
*
74+
* @return A reference to *this.
6975
*/
7076
NetworkProxySettings& WithHostname(std::string hostname);
7177

7278
/**
73-
* @brief Get proxy port.
74-
* @return proxy port.
79+
* @brief Gets the proxy port.
80+
*
81+
* @return The proxy port.
7582
*/
7683
std::uint16_t GetPort() const;
7784

7885
/**
79-
* @brief Set proxy port.
80-
* @param[in] port Proxy port.
81-
* @return reference to *this.
86+
* @brief Sets the proxy port.
87+
*
88+
* @param[in] port The proxy port.
89+
*
90+
* @return A reference to *this.
8291
*/
8392
NetworkProxySettings& WithPort(std::uint16_t port);
8493

8594
/**
86-
* @brief Get username.
87-
* @return username.
95+
* @brief Gets the username.
96+
*
97+
* @return The username.
8898
*/
8999
const std::string& GetUsername() const;
90100

91101
/**
92-
* @brief Set username.
93-
* @param[in] username
94-
* @return reference to *this.
102+
* @brief Sets the username.
103+
*
104+
* @param[in] username The username.
105+
*
106+
* @return A reference to *this.
95107
*/
96108
NetworkProxySettings& WithUsername(std::string username);
97109

98110
/**
99-
* @brief Get password.
100-
* @return password.
111+
* @brief Gets the password.
112+
*
113+
* @return The password.
101114
*/
102115
const std::string& GetPassword() const;
103116

104117
/**
105-
* @brief Set password.
106-
* @param[in] password
107-
* @return reference to *this.
118+
* @brief Sets the password.
119+
*
120+
* @param[in] password The password.
121+
*
122+
* @return A reference to *this.
108123
*/
109124
NetworkProxySettings& WithPassword(std::string password);
110125

111126
private:
112-
/// The type of the proxy.
127+
/// The proxy type.
113128
Type type_{Type::NONE};
114-
/// The port of the proxy.
129+
/// The proxy port.
115130
std::uint16_t port_{0};
116-
/// The hostname of the proxy.
131+
/// The proxy hostname.
117132
std::string hostname_;
118-
/// The username for the proxy.
133+
/// The proxy username.
119134
std::string username_;
120-
/// The password for the proxy.
135+
/// The proxy password.
121136
std::string password_;
122137
};
123138

0 commit comments

Comments
 (0)