blob: 44ed2e30f5269141f5a873019ec5ff23fe7c5b6c [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 Harishc0ea7ae2020-10-30 02:37:30 -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 Tanous8a9a25c2021-05-11 14:50:58 -070013#include <string>
14#include <string_view>
15
Ed Tanous1abe55e2018-09-05 08:30:59 -070016namespace crow
17{
Ed Tanous7045c8d2017-04-03 10:04:37 -070018
Ed Tanous1abe55e2018-09-05 08:30:59 -070019struct Request
20{
Ed Tanous43b761d2019-02-13 20:10:56 -080021 boost::beast::http::request<boost::beast::http::string_body>& req;
James Feistfe306722020-03-12 16:32:08 -070022 boost::beast::http::fields& fields;
Ed Tanous39e77502019-03-04 17:35:53 -080023 std::string_view url{};
James Feist5a7e8772020-07-22 09:08:38 -070024 boost::urls::url_view urlView{};
25 boost::urls::url_view::params_type urlParams{};
Ed Tanous1abe55e2018-09-05 08:30:59 -070026 bool isSecure{false};
Ed Tanous7045c8d2017-04-03 10:04:37 -070027
Ed Tanous1abe55e2018-09-05 08:30:59 -070028 const std::string& body;
Ed Tanouse0d918b2018-03-27 17:41:04 -070029
Ed Tanous8f626352018-12-19 14:51:54 -080030 boost::asio::io_context* ioService{};
Sunitha Harishc0ea7ae2020-10-30 02:37:30 -050031 boost::asio::ip::address ipAddress{};
Ed Tanous7045c8d2017-04-03 10:04:37 -070032
Ed Tanous52cc1122020-07-18 13:51:21 -070033 std::shared_ptr<persistent_data::UserSession> session;
Ratan Gupta6f359562019-04-03 10:39:08 +053034
RAJESWARAN THILLAIGOVINDAN61dbeef2019-12-13 04:26:54 -060035 std::string userRole{};
Ed Tanous271584a2019-07-09 16:24:22 -070036 Request(
37 boost::beast::http::request<boost::beast::http::string_body>& reqIn) :
38 req(reqIn),
James Feistfe306722020-03-12 16:32:08 -070039 fields(reqIn.base()), body(reqIn.body())
Gunnar Mills1214b7e2020-06-04 10:11:30 -050040 {}
Ed Tanous7045c8d2017-04-03 10:04:37 -070041
Ed Tanous271584a2019-07-09 16:24:22 -070042 boost::beast::http::verb method() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070043 {
44 return req.method();
45 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070046
Ed Tanous3174e4d2020-10-07 11:41:22 -070047 std::string_view getHeaderValue(std::string_view key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070048 {
49 return req[key];
50 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070051
Ed Tanous3174e4d2020-10-07 11:41:22 -070052 std::string_view getHeaderValue(boost::beast::http::field key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070053 {
54 return req[key];
55 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070056
Ed Tanous3174e4d2020-10-07 11:41:22 -070057 std::string_view methodString() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070058 {
59 return req.method_string();
60 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070061
Ed Tanous3174e4d2020-10-07 11:41:22 -070062 std::string_view target() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070063 {
64 return req.target();
65 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070066
Ed Tanous3174e4d2020-10-07 11:41:22 -070067 unsigned version() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070068 {
69 return req.version();
70 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070071
Ed Tanous3174e4d2020-10-07 11:41:22 -070072 bool isUpgrade() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070073 {
74 return boost::beast::websocket::is_upgrade(req);
75 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070076
Ed Tanous3174e4d2020-10-07 11:41:22 -070077 bool keepAlive() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070078 {
79 return req.keep_alive();
80 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070081};
Ed Tanouse0d918b2018-03-27 17:41:04 -070082
Ed Tanous1abe55e2018-09-05 08:30:59 -070083} // namespace crow