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