blob: d9d6cf723c3901b97c0e94c65703ca978f1a813c [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>
Sunitha Harishe4360082020-09-28 02:10:59 -05007#include <boost/asio/ip/address.hpp>
Ed Tanousd43cd0c2020-09-30 20:46:53 -07008#include <boost/beast/http/message.hpp>
9#include <boost/beast/http/string_body.hpp>
Manojkiran Eda44250442020-06-16 12:51:38 +053010#include <boost/beast/websocket.hpp>
James Feist5a7e8772020-07-22 09:08:38 -070011#include <boost/url/url_view.hpp>
raviteja-b4722efe2020-02-03 12:23:18 -060012
Ed Tanous1abe55e2018-09-05 08:30:59 -070013namespace crow
14{
Ed Tanous7045c8d2017-04-03 10:04:37 -070015
Ed Tanous1abe55e2018-09-05 08:30:59 -070016struct Request
17{
Ed Tanous43b761d2019-02-13 20:10:56 -080018 boost::beast::http::request<boost::beast::http::string_body>& req;
James Feistfe306722020-03-12 16:32:08 -070019 boost::beast::http::fields& fields;
Ed Tanous39e77502019-03-04 17:35:53 -080020 std::string_view url{};
James Feist5a7e8772020-07-22 09:08:38 -070021 boost::urls::url_view urlView{};
22 boost::urls::url_view::params_type urlParams{};
Ed Tanous1abe55e2018-09-05 08:30:59 -070023 bool isSecure{false};
Ed Tanous7045c8d2017-04-03 10:04:37 -070024
Ed Tanous1abe55e2018-09-05 08:30:59 -070025 const std::string& body;
Ed Tanouse0d918b2018-03-27 17:41:04 -070026
Ed Tanous8f626352018-12-19 14:51:54 -080027 boost::asio::io_context* ioService{};
Sunitha Harishe4360082020-09-28 02:10:59 -050028 boost::asio::ip::address ipAddress;
Ed Tanous7045c8d2017-04-03 10:04:37 -070029
Ed Tanous52cc1122020-07-18 13:51:21 -070030 std::shared_ptr<persistent_data::UserSession> session;
Ratan Gupta6f359562019-04-03 10:39:08 +053031
RAJESWARAN THILLAIGOVINDAN61dbeef2019-12-13 04:26:54 -060032 std::string userRole{};
Ed Tanous271584a2019-07-09 16:24:22 -070033 Request(
34 boost::beast::http::request<boost::beast::http::string_body>& reqIn) :
35 req(reqIn),
James Feistfe306722020-03-12 16:32:08 -070036 fields(reqIn.base()), body(reqIn.body())
Gunnar Mills1214b7e2020-06-04 10:11:30 -050037 {}
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 Tanous3174e4d2020-10-07 11:41:22 -070044 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 Tanous3174e4d2020-10-07 11:41:22 -070049 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 Tanous3174e4d2020-10-07 11:41:22 -070054 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 Tanous3174e4d2020-10-07 11:41:22 -070059 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 Tanous3174e4d2020-10-07 11:41:22 -070064 unsigned version() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070065 {
66 return req.version();
67 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070068
Ed Tanous3174e4d2020-10-07 11:41:22 -070069 bool isUpgrade() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070070 {
71 return boost::beast::websocket::is_upgrade(req);
72 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070073
Ed Tanous3174e4d2020-10-07 11:41:22 -070074 bool keepAlive() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070075 {
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