olp-cpp-sdk 1.24.0
Loading...
Searching...
No Matches
NetworkResponse.h
1/*
2 * Copyright (C) 2019-2025 HERE Europe B.V.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 * License-Filename: LICENSE
18 */
19
20#pragma once
21
22#include <array>
23#include <bitset>
24#include <chrono>
25#include <string>
26
27#include <olp/core/CoreApi.h>
28#include <olp/core/http/NetworkTypes.h>
29#include <olp/core/porting/optional.h>
30
31namespace olp {
32namespace http {
33
38 using MicroSeconds = std::chrono::duration<uint32_t, std::micro>;
39
40 enum Timings {
41 Queue = 0, // Delay until the request is processed
42 NameLookup, // Time taken for DNS name lookup
43 Connect, // Time taken to establish connection
44 SSL_Handshake, // Time taken to establish a secured connection
45 Send, // Time taken to send the request
46 Wait, // Time delay until server starts responding
47 Receive, // Time taken to receive the response
48 Total, // Total time taken for reqeust
49 Count
50 };
51
53 std::array<MicroSeconds, Count> timings{};
54
56 std::bitset<Count> available_timings{};
57};
58
62class CORE_API NetworkResponse final {
63 public:
69 bool IsCancelled() const;
70
76 int GetStatus() const;
77
86
93 const std::string& GetError() const;
94
104 NetworkResponse& WithError(std::string error);
105
112
121
128 uint64_t GetBytesUploaded() const;
129
138 NetworkResponse& WithBytesUploaded(uint64_t bytes_uploaded);
139
147 uint64_t GetBytesDownloaded() const;
148
157 NetworkResponse& WithBytesDownloaded(uint64_t bytes_downloaded);
158
164 const porting::optional<Diagnostics>& GetDiagnostics() const;
165
174
175 private:
177 RequestId request_id_{0};
179 int status_{0};
181 std::string error_;
183 uint64_t bytes_uploaded_{0};
185 uint64_t bytes_downloaded_{0};
187 porting::optional<Diagnostics> diagnostics_;
188};
189
190} // namespace http
191} // namespace olp
A network response abstraction for the HTTP request.
Definition NetworkResponse.h:62
int GetStatus() const
Gets the HTTP response code.
NetworkResponse & WithRequestId(RequestId id)
Sets the ID of the associated network request.
uint64_t GetBytesUploaded() const
Gets the number of bytes uploaded during the associated network request.
NetworkResponse & WithBytesUploaded(uint64_t bytes_uploaded)
Sets the number of bytes uploaded during the associated network request.
NetworkResponse & WithDiagnostics(Diagnostics diagnostics)
Sets the request diagnostics.
bool IsCancelled() const
Checks if the associated request was canceled.
RequestId GetRequestId() const
Gets the ID of the associated network request.
const std::string & GetError() const
Gets the human-readable error message if the associated request failed.
const porting::optional< Diagnostics > & GetDiagnostics() const
Gets the optional diagnostics if set.
NetworkResponse & WithBytesDownloaded(uint64_t bytes_downloaded)
Sets the number of bytes downloaded during the associated network request.
uint64_t GetBytesDownloaded() const
Gets the number of bytes downloaded during the associated network request.
NetworkResponse & WithStatus(int status)
Sets the HTTP response code.
NetworkResponse & WithError(std::string error)
Sets the human-readable error message if the associated request failed.
std::uint64_t RequestId
A unique request ID.
Definition NetworkTypes.h:41
Rules all the other namespaces.
Definition AppleSignInProperties.h:24
Network request timings.
Definition NetworkResponse.h:37
std::bitset< Count > available_timings
Availability flag, specify which timing is available.
Definition NetworkResponse.h:56
std::array< MicroSeconds, Count > timings
Timing values.
Definition NetworkResponse.h:53