SMACC2
Loading...
Searching...
No Matches
cp_http_session_manager.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 Session Manager Component - Manages SSL context and session creation
16// Authors: Claude (Anthropic AI)
17
18#pragma once
19
20#include <boost/asio/ssl/context.hpp>
24#include <memory>
25#include <smacc2/component.hpp>
26#include <string>
27
28namespace cl_http
29{
30
31// Manages SSL context and creates HTTP/HTTPS sessions based on URL
32// Parses server URL to determine protocol and port
34{
35public:
37 virtual ~CpHttpSessionManager();
38
39 void onInitialize() override;
40
41 // Configure server URL (parses protocol, host, port)
42 void setServerUrl(const std::string & server_url);
43
44 // Create HTTP or HTTPS session based on URL configuration
45 std::shared_ptr<http_session_base> createSession(
46 boost::asio::any_io_executor executor,
47 std::function<void(const http_session_base::TResponse &)> callback);
48
49 // Check if HTTPS is required
50 bool isSSL() const;
51
52 // Get server name without protocol
53 std::string getServerName() const;
54
55 // Get port number (443 for HTTPS, 80 for HTTP)
56 std::string getPort() const;
57
58private:
59 // Internal class to parse and store server configuration
61 {
62 public:
63 explicit ServerConfig(const std::string & server_name);
64
65 bool isSSL() const { return ssl_; }
66 std::string getPort() const { return ssl_ ? "443" : "80"; }
67 std::string getServerName() const { return server_name_; }
68
69 private:
70 std::string server_name_;
71 bool ssl_;
72 };
73
74 std::unique_ptr<ServerConfig> server_config_;
75 boost::asio::ssl::context ssl_context_;
77};
78
79} // namespace cl_http
boost::asio::ssl::context ssl_context_
std::shared_ptr< http_session_base > createSession(boost::asio::any_io_executor executor, std::function< void(const http_session_base::TResponse &)> callback)
void setServerUrl(const std::string &server_url)
std::unique_ptr< ServerConfig > server_config_
boost::beast::http::response< boost::beast::http::string_body > TResponse