SMACC2
Loading...
Searching...
No Matches
cp_http_request_executor.hpp
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// HTTP Request Executor Component - Executes HTTP requests and coordinates responses
16// Authors: Claude (Anthropic AI)
17
18#pragma once
19
20#include <boost/beast/http.hpp>
22#include <smacc2/component.hpp>
24#include <string>
25#include <unordered_map>
26
27namespace cl_http
28{
29
30// Forward declarations
31class CpHttpConnectionManager;
32class CpHttpSessionManager;
33
34// Coordinates HTTP request execution and emits response signals
35// Acquires strand and session from other components
37{
38public:
39 // HTTP request methods
40 enum class HttpMethod
41 {
42 GET = static_cast<int>(boost::beast::http::verb::get),
43 POST = static_cast<int>(boost::beast::http::verb::post),
44 PUT = static_cast<int>(boost::beast::http::verb::put),
45 };
46
48
50 virtual ~CpHttpRequestExecutor();
51
52 void onInitialize() override;
53
54 // Set component dependencies (called by client during initialization)
56 {
57 connectionManager_ = connMgr;
58 sessionManager_ = sessMgr;
59 }
60
61 // Execute HTTP request with specified method, path, body, and headers
62 void executeRequest(
63 const HttpMethod method, const std::string & path = "/", const std::string & body = "",
64 const std::unordered_map<std::string, std::string> & headers = {});
65
66 // Signal emitted when HTTP response is received (behaviors connect to this)
68
69private:
70 static constexpr int HTTP_VERSION = 11;
71
74
75 std::function<void(TResponse)> responseHandler_;
76};
77
78} // namespace cl_http
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={})
void setDependencies(CpHttpConnectionManager *connMgr, CpHttpSessionManager *sessMgr)
boost::beast::http::response< boost::beast::http::string_body > TResponse