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