blob: b440f4447a2f58899cdca1c63cbcdec1cf5c10e5 [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;
James Feistfe306722020-03-12 16:32:08 -070018 boost::beast::http::fields& fields;
Ed Tanous39e77502019-03-04 17:35:53 -080019 std::string_view url{};
Ed Tanous1abe55e2018-09-05 08:30:59 -070020 QueryString urlParams{};
21 bool isSecure{false};
Ed Tanous7045c8d2017-04-03 10:04:37 -070022
Ed Tanous1abe55e2018-09-05 08:30:59 -070023 const std::string& body;
Ed Tanouse0d918b2018-03-27 17:41:04 -070024
Ed Tanous1abe55e2018-09-05 08:30:59 -070025 void* middlewareContext{};
Ed Tanous8f626352018-12-19 14:51:54 -080026 boost::asio::io_context* ioService{};
Ed Tanous7045c8d2017-04-03 10:04:37 -070027
Ratan Gupta6f359562019-04-03 10:39:08 +053028 std::shared_ptr<crow::persistent_data::UserSession> session;
29
RAJESWARAN THILLAIGOVINDAN61dbeef2019-12-13 04:26:54 -060030 std::string userRole{};
31
Ed Tanous271584a2019-07-09 16:24:22 -070032 Request(
33 boost::beast::http::request<boost::beast::http::string_body>& reqIn) :
34 req(reqIn),
James Feistfe306722020-03-12 16:32:08 -070035 fields(reqIn.base()), body(reqIn.body())
Ed Tanous1abe55e2018-09-05 08:30:59 -070036 {
37 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070038
Ed Tanous271584a2019-07-09 16:24:22 -070039 boost::beast::http::verb method() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070040 {
41 return req.method();
42 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070043
Ed Tanous39e77502019-03-04 17:35:53 -080044 const std::string_view getHeaderValue(std::string_view key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070045 {
46 return req[key];
47 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070048
Ed Tanous39e77502019-03-04 17:35:53 -080049 const std::string_view getHeaderValue(boost::beast::http::field key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070050 {
51 return req[key];
52 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070053
Ed Tanous39e77502019-03-04 17:35:53 -080054 const std::string_view methodString() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070055 {
56 return req.method_string();
57 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070058
Ed Tanous39e77502019-03-04 17:35:53 -080059 const std::string_view target() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070060 {
61 return req.target();
62 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070063
Ed Tanous1abe55e2018-09-05 08:30:59 -070064 unsigned version()
65 {
66 return req.version();
67 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070068
Ed Tanous1abe55e2018-09-05 08:30:59 -070069 bool isUpgrade()
70 {
71 return boost::beast::websocket::is_upgrade(req);
72 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070073
Ed Tanous1abe55e2018-09-05 08:30:59 -070074 bool keepAlive()
75 {
76 return req.keep_alive();
77 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070078};
Ed Tanouse0d918b2018-03-27 17:41:04 -070079
Ed Tanous1abe55e2018-09-05 08:30:59 -070080} // namespace crow