Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 1 | #pragma once |
2 | |||||
Ratan Gupta | 6f35956 | 2019-04-03 10:39:08 +0530 | [diff] [blame] | 3 | #include "sessions.hpp" |
4 | |||||
Ed Tanous | 8f62635 | 2018-12-19 14:51:54 -0800 | [diff] [blame] | 5 | #include <boost/asio/io_context.hpp> |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 6 | #include <boost/beast/http.hpp> |
7 | #include <boost/beast/websocket.hpp> | ||||
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 8 | |
Ed Tanous | c94ad49 | 2019-10-10 15:39:33 -0700 | [diff] [blame] | 9 | #include "common.h" |
10 | #include "query_string.h" | ||||
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 11 | |
raviteja-b | 4722efe | 2020-02-03 12:23:18 -0600 | [diff] [blame^] | 12 | #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 Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 18 | namespace crow |
19 | { | ||||
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 20 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 21 | struct Request |
22 | { | ||||
raviteja-b | 4722efe | 2020-02-03 12:23:18 -0600 | [diff] [blame^] | 23 | #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 Tanous | 43b761d | 2019-02-13 20:10:56 -0800 | [diff] [blame] | 29 | boost::beast::http::request<boost::beast::http::string_body>& req; |
James Feist | fe30672 | 2020-03-12 16:32:08 -0700 | [diff] [blame] | 30 | boost::beast::http::fields& fields; |
Ed Tanous | 39e7750 | 2019-03-04 17:35:53 -0800 | [diff] [blame] | 31 | std::string_view url{}; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 32 | QueryString urlParams{}; |
33 | bool isSecure{false}; | ||||
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 34 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 35 | const std::string& body; |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 36 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 37 | void* middlewareContext{}; |
Ed Tanous | 8f62635 | 2018-12-19 14:51:54 -0800 | [diff] [blame] | 38 | boost::asio::io_context* ioService{}; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 39 | |
Ratan Gupta | 6f35956 | 2019-04-03 10:39:08 +0530 | [diff] [blame] | 40 | std::shared_ptr<crow::persistent_data::UserSession> session; |
41 | |||||
RAJESWARAN THILLAIGOVINDAN | 61dbeef | 2019-12-13 04:26:54 -0600 | [diff] [blame] | 42 | std::string userRole{}; |
raviteja-b | 4722efe | 2020-02-03 12:23:18 -0600 | [diff] [blame^] | 43 | std::function<Adaptor&()> socket; |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 44 | Request( |
45 | boost::beast::http::request<boost::beast::http::string_body>& reqIn) : | ||||
46 | req(reqIn), | ||||
James Feist | fe30672 | 2020-03-12 16:32:08 -0700 | [diff] [blame] | 47 | fields(reqIn.base()), body(reqIn.body()) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 48 | { |
49 | } | ||||
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 50 | |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 51 | boost::beast::http::verb method() const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 52 | { |
53 | return req.method(); | ||||
54 | } | ||||
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 55 | |
Ed Tanous | 39e7750 | 2019-03-04 17:35:53 -0800 | [diff] [blame] | 56 | const std::string_view getHeaderValue(std::string_view key) const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 57 | { |
58 | return req[key]; | ||||
59 | } | ||||
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 60 | |
Ed Tanous | 39e7750 | 2019-03-04 17:35:53 -0800 | [diff] [blame] | 61 | const std::string_view getHeaderValue(boost::beast::http::field key) const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 62 | { |
63 | return req[key]; | ||||
64 | } | ||||
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 65 | |
Ed Tanous | 39e7750 | 2019-03-04 17:35:53 -0800 | [diff] [blame] | 66 | const std::string_view methodString() const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 67 | { |
68 | return req.method_string(); | ||||
69 | } | ||||
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 70 | |
Ed Tanous | 39e7750 | 2019-03-04 17:35:53 -0800 | [diff] [blame] | 71 | const std::string_view target() const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 72 | { |
73 | return req.target(); | ||||
74 | } | ||||
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 75 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 76 | unsigned version() |
77 | { | ||||
78 | return req.version(); | ||||
79 | } | ||||
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 80 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 81 | bool isUpgrade() |
82 | { | ||||
83 | return boost::beast::websocket::is_upgrade(req); | ||||
84 | } | ||||
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 85 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 86 | bool keepAlive() |
87 | { | ||||
88 | return req.keep_alive(); | ||||
89 | } | ||||
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 90 | }; |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 91 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 92 | } // namespace crow |