blob: e5c0c9e982c0ac44cb14607dce7bbe8ee1e860e5 [file] [log] [blame]
Ed Tanous7045c8d2017-04-03 10:04:37 -07001#pragma once
2
Ed Tanous04e438c2020-10-03 08:06:26 -07003#include "common.hpp"
Ratan Gupta6f359562019-04-03 10:39:08 +05304#include "sessions.hpp"
5
Ed Tanous8f626352018-12-19 14:51:54 -08006#include <boost/asio/io_context.hpp>
Ed Tanousd43cd0c2020-09-30 20:46:53 -07007#include <boost/beast/http/message.hpp>
8#include <boost/beast/http/string_body.hpp>
Manojkiran Eda44250442020-06-16 12:51:38 +05309#include <boost/beast/websocket.hpp>
James Feist5a7e8772020-07-22 09:08:38 -070010#include <boost/url/url_view.hpp>
raviteja-b4722efe2020-02-03 12:23:18 -060011
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{};
James Feist5a7e8772020-07-22 09:08:38 -070020 boost::urls::url_view urlView{};
21 boost::urls::url_view::params_type urlParams{};
Ed Tanous1abe55e2018-09-05 08:30:59 -070022 bool isSecure{false};
Ed Tanous7045c8d2017-04-03 10:04:37 -070023
Ed Tanous1abe55e2018-09-05 08:30:59 -070024 const std::string& body;
Ed Tanouse0d918b2018-03-27 17:41:04 -070025
Ed Tanous8f626352018-12-19 14:51:54 -080026 boost::asio::io_context* ioService{};
Ed Tanous7045c8d2017-04-03 10:04:37 -070027
Ed Tanous52cc1122020-07-18 13:51:21 -070028 std::shared_ptr<persistent_data::UserSession> session;
Ratan Gupta6f359562019-04-03 10:39:08 +053029
RAJESWARAN THILLAIGOVINDAN61dbeef2019-12-13 04:26:54 -060030 std::string userRole{};
Ed Tanous271584a2019-07-09 16:24:22 -070031 Request(
32 boost::beast::http::request<boost::beast::http::string_body>& reqIn) :
33 req(reqIn),
James Feistfe306722020-03-12 16:32:08 -070034 fields(reqIn.base()), body(reqIn.body())
Gunnar Mills1214b7e2020-06-04 10:11:30 -050035 {}
Ed Tanous7045c8d2017-04-03 10:04:37 -070036
Ed Tanous271584a2019-07-09 16:24:22 -070037 boost::beast::http::verb method() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070038 {
39 return req.method();
40 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070041
Ed Tanous3174e4d2020-10-07 11:41:22 -070042 std::string_view getHeaderValue(std::string_view key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070043 {
44 return req[key];
45 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070046
Ed Tanous3174e4d2020-10-07 11:41:22 -070047 std::string_view getHeaderValue(boost::beast::http::field key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070048 {
49 return req[key];
50 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070051
Ed Tanous3174e4d2020-10-07 11:41:22 -070052 std::string_view methodString() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070053 {
54 return req.method_string();
55 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070056
Ed Tanous3174e4d2020-10-07 11:41:22 -070057 std::string_view target() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070058 {
59 return req.target();
60 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070061
Ed Tanous3174e4d2020-10-07 11:41:22 -070062 unsigned version() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070063 {
64 return req.version();
65 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070066
Ed Tanous3174e4d2020-10-07 11:41:22 -070067 bool isUpgrade() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070068 {
69 return boost::beast::websocket::is_upgrade(req);
70 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070071
Ed Tanous3174e4d2020-10-07 11:41:22 -070072 bool keepAlive() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070073 {
74 return req.keep_alive();
75 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070076};
Ed Tanouse0d918b2018-03-27 17:41:04 -070077
Ed Tanous1abe55e2018-09-05 08:30:59 -070078} // namespace crow