Skip to content

Commit dff33b8

Browse files
Add HarCaptureAdapter class
Implement HarCaptureAdapter to capture network requests and generate HAR files. It is capable to capture network requests along with headers, status codes, transfer sizes and timings. Relates-To: OCMAM-418 Signed-off-by: Mykhailo Kuchma <ext-mykhailo.kuchma@here.com>
1 parent e80ea0b commit dff33b8

File tree

3 files changed

+465
-0
lines changed

3 files changed

+465
-0
lines changed

olp-cpp-sdk-core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ set(OLP_SDK_GENERATED_HEADERS
104104
)
105105

106106
set(OLP_SDK_HTTP_HEADERS
107+
./include/olp/core/http/adapters/HarCaptureAdapter.h
107108
./include/olp/core/http/CertificateSettings.h
108109
./include/olp/core/http/HttpStatusCode.h
109110
./include/olp/core/http/Network.h
@@ -288,6 +289,7 @@ set(OLP_SDK_CLIENT_SOURCES
288289
)
289290

290291
set(OLP_SDK_HTTP_SOURCES
292+
./src/http/adapters/HarCaptureAdapter.cpp
291293
./src/http/DefaultNetwork.cpp
292294
./src/http/DefaultNetwork.h
293295
./src/http/Network.cpp
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (C) 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 <string>
23+
#include <memory>
24+
25+
#include <olp/core/CoreApi.h>
26+
#include <olp/core/http/Network.h>
27+
28+
namespace olp {
29+
namespace http {
30+
31+
/**
32+
* @class HarCaptureAdapter
33+
* @brief A network adapter that captures HTTP requests and responses,
34+
* generating a HAR (HTTP Archive) file.
35+
*
36+
* HarCaptureAdapter implements the olp::http::Network interface, intercepting
37+
* network traffic for debugging, logging, and analysis. It records request
38+
* metadata, headers, and response details, allowing developers to
39+
* inspect network interactions in HAR format.
40+
*
41+
* @note Request timings are only available when Curl is used.
42+
* @note The HAR file is produced when the instance is destroyed.
43+
*
44+
* Features:
45+
* - Captures HTTP requests and responses.
46+
* - Logs request/response details, including headers, status codes and timings.
47+
* - Generates a HAR file for easy debugging and sharing.
48+
*
49+
* Example Usage:
50+
* @code
51+
* auto network = std::make_shared<HarCaptureAdapter>(network, "/tmp/out.har");
52+
* @endcode
53+
*/
54+
class CORE_API HarCaptureAdapter final : public Network {
55+
public:
56+
/**
57+
* @brief Constructs a HarCaptureAdapter instance.
58+
*
59+
* @param network The underlying network implementation to forward requests
60+
* to.
61+
* @param har_out_path The file path where the HAR (HTTP Archive) file will be
62+
* saved.
63+
*/
64+
HarCaptureAdapter(std::shared_ptr<Network> network, std::string har_out_path);
65+
66+
~HarCaptureAdapter() override;
67+
68+
/**
69+
* @copydoc Network::Send
70+
*/
71+
SendOutcome Send(NetworkRequest request, Payload payload, Callback callback,
72+
HeaderCallback header_callback,
73+
DataCallback data_callback) override;
74+
75+
/**
76+
* @copydoc Network::Cancel
77+
*/
78+
void Cancel(RequestId id) override;
79+
80+
private:
81+
class HarCaptureAdapterImpl;
82+
std::shared_ptr<HarCaptureAdapterImpl> impl_;
83+
};
84+
85+
} // namespace http
86+
} // namespace olp

0 commit comments

Comments
 (0)