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