SMACC2
Loading...
Searching...
No Matches
cp_http_request_executor.cpp
Go to the documentation of this file.
1// Copyright 2024 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Claude (Anthropic AI)
18 *
19 ******************************************************************************************************************/
20
24
25namespace cl_http
26{
27
29: connectionManager_(nullptr), sessionManager_(nullptr)
30{
31 responseHandler_ = [this](const TResponse & res) { onResponseReceived_(res); };
32}
33
35
37{
38 // Dependencies set via setDependencies() before onInitialize() is called
39}
40
42 const HttpMethod method, const std::string & path, const std::string & body,
43 const std::unordered_map<std::string, std::string> & headers)
44{
45 auto path_used = path;
46 if (path.empty() || path[0] != '/')
47 {
48 path_used = "/" + path;
49 }
50
51 RCLCPP_INFO(
52 this->getLogger(), "Executing request: SSL=%d Server=%s Path=%s Port=%s",
53 sessionManager_->isSSL(), sessionManager_->getServerName().c_str(), path_used.c_str(),
54 sessionManager_->getPort().c_str());
55
56 auto executor = connectionManager_->getStrand();
57 auto session = sessionManager_->createSession(executor, responseHandler_);
58
59 session->setBody(body);
60 session->setHeaders(headers);
61 session->run(
62 sessionManager_->getServerName(), path_used, static_cast<boost::beast::http::verb>(method),
64}
65
66} // namespace cl_http
boost::asio::any_io_executor getStrand()
http_session_base::TResponse TResponse
smacc2::SmaccSignal< void(const TResponse &)> onResponseReceived_
std::function< void(TResponse)> responseHandler_
CpHttpConnectionManager * connectionManager_
void executeRequest(const HttpMethod method, const std::string &path="/", const std::string &body="", const std::unordered_map< std::string, std::string > &headers={})
std::shared_ptr< http_session_base > createSession(boost::asio::any_io_executor executor, std::function< void(const http_session_base::TResponse &)> callback)
rclcpp::Logger getLogger() const