1 #pragma once 2 3 #include "common.hpp" 4 #include "sessions.hpp" 5 6 #include <boost/asio/io_context.hpp> 7 #include <boost/beast/http/message.hpp> 8 #include <boost/beast/http/string_body.hpp> 9 #include <boost/beast/websocket.hpp> 10 #include <boost/url/url_view.hpp> 11 12 namespace crow 13 { 14 15 struct Request 16 { 17 boost::beast::http::request<boost::beast::http::string_body>& req; 18 boost::beast::http::fields& fields; 19 std::string_view url{}; 20 boost::urls::url_view urlView{}; 21 boost::urls::url_view::params_type urlParams{}; 22 bool isSecure{false}; 23 24 const std::string& body; 25 26 boost::asio::io_context* ioService{}; 27 28 std::shared_ptr<persistent_data::UserSession> session; 29 30 std::string userRole{}; 31 Request( 32 boost::beast::http::request<boost::beast::http::string_body>& reqIn) : 33 req(reqIn), 34 fields(reqIn.base()), body(reqIn.body()) 35 {} 36 37 boost::beast::http::verb method() const 38 { 39 return req.method(); 40 } 41 42 std::string_view getHeaderValue(std::string_view key) const 43 { 44 return req[key]; 45 } 46 47 std::string_view getHeaderValue(boost::beast::http::field key) const 48 { 49 return req[key]; 50 } 51 52 std::string_view methodString() const 53 { 54 return req.method_string(); 55 } 56 57 std::string_view target() const 58 { 59 return req.target(); 60 } 61 62 unsigned version() const 63 { 64 return req.version(); 65 } 66 67 bool isUpgrade() const 68 { 69 return boost::beast::websocket::is_upgrade(req); 70 } 71 72 bool keepAlive() const 73 { 74 return req.keep_alive(); 75 } 76 }; 77 78 } // namespace crow 79