blob: ff09bf10295c6e023f250041dfc76b00897b27de [file] [log] [blame]
Ed Tanous7045c8d2017-04-03 10:04:37 -07001#pragma once
2
Ratan Gupta6f359562019-04-03 10:39:08 +05303#include "sessions.hpp"
4
Ed Tanous8f626352018-12-19 14:51:54 -08005#include <boost/asio/io_context.hpp>
Ed Tanouse0d918b2018-03-27 17:41:04 -07006#include <boost/beast/http.hpp>
7#include <boost/beast/websocket.hpp>
Ed Tanous7045c8d2017-04-03 10:04:37 -07008
Ed Tanousc94ad492019-10-10 15:39:33 -07009#include "common.h"
10#include "query_string.h"
Ed Tanous7045c8d2017-04-03 10:04:37 -070011
Ed Tanous1abe55e2018-09-05 08:30:59 -070012namespace crow
13{
Ed Tanous7045c8d2017-04-03 10:04:37 -070014
Ed Tanous1abe55e2018-09-05 08:30:59 -070015struct Request
16{
Ed Tanous43b761d2019-02-13 20:10:56 -080017 boost::beast::http::request<boost::beast::http::string_body>& req;
Ed Tanous39e77502019-03-04 17:35:53 -080018 std::string_view url{};
Ed Tanous1abe55e2018-09-05 08:30:59 -070019 QueryString urlParams{};
20 bool isSecure{false};
Ed Tanous7045c8d2017-04-03 10:04:37 -070021
Ed Tanous1abe55e2018-09-05 08:30:59 -070022 const std::string& body;
Ed Tanouse0d918b2018-03-27 17:41:04 -070023
Ed Tanous1abe55e2018-09-05 08:30:59 -070024 void* middlewareContext{};
Ed Tanous8f626352018-12-19 14:51:54 -080025 boost::asio::io_context* ioService{};
Ed Tanous7045c8d2017-04-03 10:04:37 -070026
Ratan Gupta6f359562019-04-03 10:39:08 +053027 std::shared_ptr<crow::persistent_data::UserSession> session;
28
RAJESWARAN THILLAIGOVINDAN61dbeef2019-12-13 04:26:54 -060029 std::string userRole{};
30
Ed Tanous271584a2019-07-09 16:24:22 -070031 Request(
32 boost::beast::http::request<boost::beast::http::string_body>& reqIn) :
33 req(reqIn),
34 body(reqIn.body())
Ed Tanous1abe55e2018-09-05 08:30:59 -070035 {
36 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070037
Ed Tanous271584a2019-07-09 16:24:22 -070038 boost::beast::http::verb method() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070039 {
40 return req.method();
41 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070042
Ed Tanous39e77502019-03-04 17:35:53 -080043 const std::string_view getHeaderValue(std::string_view key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070044 {
45 return req[key];
46 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070047
Ed Tanous39e77502019-03-04 17:35:53 -080048 const std::string_view getHeaderValue(boost::beast::http::field key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070049 {
50 return req[key];
51 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070052
Ed Tanous39e77502019-03-04 17:35:53 -080053 const std::string_view methodString() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070054 {
55 return req.method_string();
56 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070057
Ed Tanous39e77502019-03-04 17:35:53 -080058 const std::string_view target() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070059 {
60 return req.target();
61 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070062
Ed Tanous1abe55e2018-09-05 08:30:59 -070063 unsigned version()
64 {
65 return req.version();
66 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070067
Ed Tanous1abe55e2018-09-05 08:30:59 -070068 bool isUpgrade()
69 {
70 return boost::beast::websocket::is_upgrade(req);
71 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070072
Ed Tanous1abe55e2018-09-05 08:30:59 -070073 bool keepAlive()
74 {
75 return req.keep_alive();
76 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070077};
Ed Tanouse0d918b2018-03-27 17:41:04 -070078
Ed Tanous1abe55e2018-09-05 08:30:59 -070079} // namespace crow