SMACC2
Loading...
Searching...
No Matches
http_session_base.hpp
Go to the documentation of this file.
1// Copyright 2021 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
18Author: Jacobus Lock
19
20******************************************************************************************************************/
21
22#pragma once
23
24#include <boost/asio/executor_work_guard.hpp>
25#include <boost/asio/strand.hpp>
26#include <boost/beast/core.hpp>
27#include <boost/beast/http.hpp>
28#include <boost/beast/ssl.hpp>
29#include <boost/beast/version.hpp>
30#include <string>
31
32namespace cl_http
33{
35{
36public:
37 virtual ~http_session_base() {}
38
39 using TResponse = boost::beast::http::response<boost::beast::http::string_body>;
40
41 // Start the asynchronous operation
42 virtual void run(
43 const std::string & host, const std::string & target,
44 const boost::beast::http::verb http_method, const int & version) = 0;
45
46 virtual std::string getPort() = 0;
47 virtual void setBody(const std::string & body) = 0;
48 virtual void setHeaders(const std::unordered_map<std::string, std::string> & headers) = 0;
49
50protected:
51 virtual void on_resolve(
52 boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type results) = 0;
53 virtual void fail(boost::beast::error_code ec, const char * what) = 0;
54 virtual void on_connect(
55 boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type::endpoint_type) = 0;
56 virtual void on_write(boost::beast::error_code ec, std::size_t bytes_transferred) = 0;
57 virtual void on_read(boost::beast::error_code ec, std::size_t bytes_transferred) = 0;
58
59 // Optional, needed for SSL connections
60 virtual void on_handshake(boost::beast::error_code ec) {}
61 virtual void on_shutdown(boost::beast::error_code ec) {}
62};
63} // namespace cl_http
virtual void setBody(const std::string &body)=0
virtual void on_connect(boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type::endpoint_type)=0
virtual void setHeaders(const std::unordered_map< std::string, std::string > &headers)=0
virtual void on_shutdown(boost::beast::error_code ec)
virtual void on_write(boost::beast::error_code ec, std::size_t bytes_transferred)=0
virtual std::string getPort()=0
virtual void on_resolve(boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type results)=0
virtual void fail(boost::beast::error_code ec, const char *what)=0
virtual void on_read(boost::beast::error_code ec, std::size_t bytes_transferred)=0
boost::beast::http::response< boost::beast::http::string_body > TResponse
virtual void run(const std::string &host, const std::string &target, const boost::beast::http::verb http_method, const int &version)=0
virtual void on_handshake(boost::beast::error_code ec)