blob: 95f88c735d5d7dfb8bb76d2a9f008e71a52e75c0 [file] [log] [blame]
Ed Tanous7045c8d2017-04-03 10:04:37 -07001#pragma once
2
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003#include "common.h"
Gunnar Mills1214b7e2020-06-04 10:11:30 -05004
Ratan Gupta6f359562019-04-03 10:39:08 +05305#include "sessions.hpp"
6
Ed Tanous8f626352018-12-19 14:51:54 -08007#include <boost/asio/io_context.hpp>
Ed Tanouse0d918b2018-03-27 17:41:04 -07008#include <boost/beast/http.hpp>
raviteja-b4722efe2020-02-03 12:23:18 -06009#include <boost/beast/ssl/ssl_stream.hpp>
Manojkiran Eda44250442020-06-16 12:51:38 +053010#include <boost/beast/websocket.hpp>
James Feist5a7e8772020-07-22 09:08:38 -070011#include <boost/url/url_view.hpp>
raviteja-b4722efe2020-02-03 12:23:18 -060012
Ed Tanous1abe55e2018-09-05 08:30:59 -070013namespace crow
14{
Ed Tanous7045c8d2017-04-03 10:04:37 -070015
Ed Tanous1abe55e2018-09-05 08:30:59 -070016struct Request
17{
raviteja-b4722efe2020-02-03 12:23:18 -060018#ifdef BMCWEB_ENABLE_SSL
19 using Adaptor = boost::beast::ssl_stream<boost::asio::ip::tcp::socket>;
20#else
21 using Adaptor = boost::asio::ip::tcp::socket;
22#endif
23
Ed Tanous43b761d2019-02-13 20:10:56 -080024 boost::beast::http::request<boost::beast::http::string_body>& req;
James Feistfe306722020-03-12 16:32:08 -070025 boost::beast::http::fields& fields;
Ed Tanous39e77502019-03-04 17:35:53 -080026 std::string_view url{};
James Feist5a7e8772020-07-22 09:08:38 -070027 boost::urls::url_view urlView{};
28 boost::urls::url_view::params_type urlParams{};
Ed Tanous1abe55e2018-09-05 08:30:59 -070029 bool isSecure{false};
Ed Tanous7045c8d2017-04-03 10:04:37 -070030
Ed Tanous1abe55e2018-09-05 08:30:59 -070031 const std::string& body;
Ed Tanouse0d918b2018-03-27 17:41:04 -070032
Ed Tanous1abe55e2018-09-05 08:30:59 -070033 void* middlewareContext{};
Ed Tanous8f626352018-12-19 14:51:54 -080034 boost::asio::io_context* ioService{};
Ed Tanous7045c8d2017-04-03 10:04:37 -070035
Ratan Gupta6f359562019-04-03 10:39:08 +053036 std::shared_ptr<crow::persistent_data::UserSession> session;
37
RAJESWARAN THILLAIGOVINDAN61dbeef2019-12-13 04:26:54 -060038 std::string userRole{};
raviteja-b4722efe2020-02-03 12:23:18 -060039 std::function<Adaptor&()> socket;
Ed Tanous271584a2019-07-09 16:24:22 -070040 Request(
41 boost::beast::http::request<boost::beast::http::string_body>& reqIn) :
42 req(reqIn),
James Feistfe306722020-03-12 16:32:08 -070043 fields(reqIn.base()), body(reqIn.body())
Gunnar Mills1214b7e2020-06-04 10:11:30 -050044 {}
Ed Tanous7045c8d2017-04-03 10:04:37 -070045
Ed Tanous271584a2019-07-09 16:24:22 -070046 boost::beast::http::verb method() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070047 {
48 return req.method();
49 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070050
Ed Tanous39e77502019-03-04 17:35:53 -080051 const std::string_view getHeaderValue(std::string_view key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070052 {
53 return req[key];
54 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070055
Ed Tanous39e77502019-03-04 17:35:53 -080056 const std::string_view getHeaderValue(boost::beast::http::field key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070057 {
58 return req[key];
59 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070060
Ed Tanous39e77502019-03-04 17:35:53 -080061 const std::string_view methodString() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070062 {
63 return req.method_string();
64 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070065
Ed Tanous39e77502019-03-04 17:35:53 -080066 const std::string_view target() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070067 {
68 return req.target();
69 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070070
Ed Tanous1abe55e2018-09-05 08:30:59 -070071 unsigned version()
72 {
73 return req.version();
74 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070075
Ed Tanous1abe55e2018-09-05 08:30:59 -070076 bool isUpgrade()
77 {
78 return boost::beast::websocket::is_upgrade(req);
79 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070080
Ed Tanous1abe55e2018-09-05 08:30:59 -070081 bool keepAlive()
82 {
83 return req.keep_alive();
84 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070085};
Ed Tanouse0d918b2018-03-27 17:41:04 -070086
Ed Tanous1abe55e2018-09-05 08:30:59 -070087} // namespace crow