blob: c3e497f1b74ad180ebeb48c7db80b6ac266a9ff4 [file] [log] [blame]
Ed Tanous7045c8d2017-04-03 10:04:37 -07001#pragma once
2
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003#include "common.h"
Gunnar Mills1214b7e2020-06-04 10:11:30 -05004
Ratan Gupta6f359562019-04-03 10:39:08 +05305#include "sessions.hpp"
6
Ed Tanous8f626352018-12-19 14:51:54 -08007#include <boost/asio/io_context.hpp>
Sunitha Harishe4360082020-09-28 02:10:59 -05008#include <boost/asio/ip/address.hpp>
Ed Tanousd43cd0c2020-09-30 20:46:53 -07009#include <boost/beast/http/message.hpp>
10#include <boost/beast/http/string_body.hpp>
Manojkiran Eda44250442020-06-16 12:51:38 +053011#include <boost/beast/websocket.hpp>
James Feist5a7e8772020-07-22 09:08:38 -070012#include <boost/url/url_view.hpp>
raviteja-b4722efe2020-02-03 12:23:18 -060013
Ed Tanous1abe55e2018-09-05 08:30:59 -070014namespace crow
15{
Ed Tanous7045c8d2017-04-03 10:04:37 -070016
Ed Tanous1abe55e2018-09-05 08:30:59 -070017struct Request
18{
Ed Tanous43b761d2019-02-13 20:10:56 -080019 boost::beast::http::request<boost::beast::http::string_body>& req;
James Feistfe306722020-03-12 16:32:08 -070020 boost::beast::http::fields& fields;
Ed Tanous39e77502019-03-04 17:35:53 -080021 std::string_view url{};
James Feist5a7e8772020-07-22 09:08:38 -070022 boost::urls::url_view urlView{};
23 boost::urls::url_view::params_type urlParams{};
Ed Tanous1abe55e2018-09-05 08:30:59 -070024 bool isSecure{false};
Ed Tanous7045c8d2017-04-03 10:04:37 -070025
Ed Tanous1abe55e2018-09-05 08:30:59 -070026 const std::string& body;
Ed Tanouse0d918b2018-03-27 17:41:04 -070027
Ed Tanous8f626352018-12-19 14:51:54 -080028 boost::asio::io_context* ioService{};
Sunitha Harishe4360082020-09-28 02:10:59 -050029 boost::asio::ip::address ipAddress;
Ed Tanous7045c8d2017-04-03 10:04:37 -070030
Ed Tanous52cc1122020-07-18 13:51:21 -070031 std::shared_ptr<persistent_data::UserSession> session;
Ratan Gupta6f359562019-04-03 10:39:08 +053032
RAJESWARAN THILLAIGOVINDAN61dbeef2019-12-13 04:26:54 -060033 std::string userRole{};
Ed Tanous271584a2019-07-09 16:24:22 -070034 Request(
35 boost::beast::http::request<boost::beast::http::string_body>& reqIn) :
36 req(reqIn),
James Feistfe306722020-03-12 16:32:08 -070037 fields(reqIn.base()), body(reqIn.body())
Gunnar Mills1214b7e2020-06-04 10:11:30 -050038 {}
Ed Tanous7045c8d2017-04-03 10:04:37 -070039
Ed Tanous271584a2019-07-09 16:24:22 -070040 boost::beast::http::verb method() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070041 {
42 return req.method();
43 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070044
Ed Tanous3174e4d2020-10-07 11:41:22 -070045 std::string_view getHeaderValue(std::string_view key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070046 {
47 return req[key];
48 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070049
Ed Tanous3174e4d2020-10-07 11:41:22 -070050 std::string_view getHeaderValue(boost::beast::http::field key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070051 {
52 return req[key];
53 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070054
Ed Tanous3174e4d2020-10-07 11:41:22 -070055 std::string_view methodString() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070056 {
57 return req.method_string();
58 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070059
Ed Tanous3174e4d2020-10-07 11:41:22 -070060 std::string_view target() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070061 {
62 return req.target();
63 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070064
Ed Tanous3174e4d2020-10-07 11:41:22 -070065 unsigned version() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070066 {
67 return req.version();
68 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070069
Ed Tanous3174e4d2020-10-07 11:41:22 -070070 bool isUpgrade() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070071 {
72 return boost::beast::websocket::is_upgrade(req);
73 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070074
Ed Tanous3174e4d2020-10-07 11:41:22 -070075 bool keepAlive() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070076 {
77 return req.keep_alive();
78 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070079};
Ed Tanouse0d918b2018-03-27 17:41:04 -070080
Ed Tanous1abe55e2018-09-05 08:30:59 -070081} // namespace crow