blob: 0dd7e35f9523428b0d6b0b2fa6387b5b0a2769d7 [file] [log] [blame]
Ed Tanous7045c8d2017-04-03 10:04:37 -07001#pragma once
2
Ratan Gupta6f359562019-04-03 10:39:08 +05303#include "sessions.hpp"
4
Ed Tanous8f626352018-12-19 14:51:54 -08005#include <boost/asio/io_context.hpp>
Ed Tanouse0d918b2018-03-27 17:41:04 -07006#include <boost/beast/http.hpp>
7#include <boost/beast/websocket.hpp>
Ed Tanous7045c8d2017-04-03 10:04:37 -07008
Ed Tanousc94ad492019-10-10 15:39:33 -07009#include "common.h"
10#include "query_string.h"
Ed Tanous7045c8d2017-04-03 10:04:37 -070011
raviteja-b4722efe2020-02-03 12:23:18 -060012#if BOOST_VERSION >= 107000
13#include <boost/beast/ssl/ssl_stream.hpp>
14#else
15#include <boost/beast/experimental/core/ssl_stream.hpp>
16#endif
17
Ed Tanous1abe55e2018-09-05 08:30:59 -070018namespace crow
19{
Ed Tanous7045c8d2017-04-03 10:04:37 -070020
Ed Tanous1abe55e2018-09-05 08:30:59 -070021struct Request
22{
raviteja-b4722efe2020-02-03 12:23:18 -060023#ifdef BMCWEB_ENABLE_SSL
24 using Adaptor = boost::beast::ssl_stream<boost::asio::ip::tcp::socket>;
25#else
26 using Adaptor = boost::asio::ip::tcp::socket;
27#endif
28
Ed Tanous43b761d2019-02-13 20:10:56 -080029 boost::beast::http::request<boost::beast::http::string_body>& req;
James Feistfe306722020-03-12 16:32:08 -070030 boost::beast::http::fields& fields;
Ed Tanous39e77502019-03-04 17:35:53 -080031 std::string_view url{};
Ed Tanous1abe55e2018-09-05 08:30:59 -070032 QueryString urlParams{};
33 bool isSecure{false};
Ed Tanous7045c8d2017-04-03 10:04:37 -070034
Ed Tanous1abe55e2018-09-05 08:30:59 -070035 const std::string& body;
Ed Tanouse0d918b2018-03-27 17:41:04 -070036
Ed Tanous1abe55e2018-09-05 08:30:59 -070037 void* middlewareContext{};
Ed Tanous8f626352018-12-19 14:51:54 -080038 boost::asio::io_context* ioService{};
Ed Tanous7045c8d2017-04-03 10:04:37 -070039
Ratan Gupta6f359562019-04-03 10:39:08 +053040 std::shared_ptr<crow::persistent_data::UserSession> session;
41
RAJESWARAN THILLAIGOVINDAN61dbeef2019-12-13 04:26:54 -060042 std::string userRole{};
raviteja-b4722efe2020-02-03 12:23:18 -060043 std::function<Adaptor&()> socket;
Ed Tanous271584a2019-07-09 16:24:22 -070044 Request(
45 boost::beast::http::request<boost::beast::http::string_body>& reqIn) :
46 req(reqIn),
James Feistfe306722020-03-12 16:32:08 -070047 fields(reqIn.base()), body(reqIn.body())
Ed Tanous1abe55e2018-09-05 08:30:59 -070048 {
49 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070050
Ed Tanous271584a2019-07-09 16:24:22 -070051 boost::beast::http::verb method() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070052 {
53 return req.method();
54 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070055
Ed Tanous39e77502019-03-04 17:35:53 -080056 const std::string_view getHeaderValue(std::string_view key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070057 {
58 return req[key];
59 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070060
Ed Tanous39e77502019-03-04 17:35:53 -080061 const std::string_view getHeaderValue(boost::beast::http::field key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070062 {
63 return req[key];
64 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070065
Ed Tanous39e77502019-03-04 17:35:53 -080066 const std::string_view methodString() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070067 {
68 return req.method_string();
69 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070070
Ed Tanous39e77502019-03-04 17:35:53 -080071 const std::string_view target() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070072 {
73 return req.target();
74 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070075
Ed Tanous1abe55e2018-09-05 08:30:59 -070076 unsigned version()
77 {
78 return req.version();
79 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070080
Ed Tanous1abe55e2018-09-05 08:30:59 -070081 bool isUpgrade()
82 {
83 return boost::beast::websocket::is_upgrade(req);
84 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070085
Ed Tanous1abe55e2018-09-05 08:30:59 -070086 bool keepAlive()
87 {
88 return req.keep_alive();
89 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070090};
Ed Tanouse0d918b2018-03-27 17:41:04 -070091
Ed Tanous1abe55e2018-09-05 08:30:59 -070092} // namespace crow