blob: 67cc944af65ba18f11674ece9a74c41b0b6f134e [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"
4#include "query_string.h"
5
Ratan Gupta6f359562019-04-03 10:39:08 +05306#include "sessions.hpp"
7
Ed Tanous8f626352018-12-19 14:51:54 -08008#include <boost/asio/io_context.hpp>
Ed Tanouse0d918b2018-03-27 17:41:04 -07009#include <boost/beast/http.hpp>
10#include <boost/beast/websocket.hpp>
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())
Gunnar Mills1214b7e2020-06-04 10:11:30 -050048 {}
Ed Tanous7045c8d2017-04-03 10:04:37 -070049
Ed Tanous271584a2019-07-09 16:24:22 -070050 boost::beast::http::verb method() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070051 {
52 return req.method();
53 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070054
Ed Tanous39e77502019-03-04 17:35:53 -080055 const std::string_view getHeaderValue(std::string_view key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070056 {
57 return req[key];
58 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070059
Ed Tanous39e77502019-03-04 17:35:53 -080060 const std::string_view getHeaderValue(boost::beast::http::field key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070061 {
62 return req[key];
63 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070064
Ed Tanous39e77502019-03-04 17:35:53 -080065 const std::string_view methodString() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070066 {
67 return req.method_string();
68 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070069
Ed Tanous39e77502019-03-04 17:35:53 -080070 const std::string_view target() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070071 {
72 return req.target();
73 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070074
Ed Tanous1abe55e2018-09-05 08:30:59 -070075 unsigned version()
76 {
77 return req.version();
78 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070079
Ed Tanous1abe55e2018-09-05 08:30:59 -070080 bool isUpgrade()
81 {
82 return boost::beast::websocket::is_upgrade(req);
83 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070084
Ed Tanous1abe55e2018-09-05 08:30:59 -070085 bool keepAlive()
86 {
87 return req.keep_alive();
88 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070089};
Ed Tanouse0d918b2018-03-27 17:41:04 -070090
Ed Tanous1abe55e2018-09-05 08:30:59 -070091} // namespace crow