blob: caae93a1a5f2a58d5b11142cc77577da0e1ba33c [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;
Ed Tanous39e77502019-03-04 17:35:53 -080018 std::string_view url{};
Ed Tanous1abe55e2018-09-05 08:30:59 -070019 QueryString urlParams{};
20 bool isSecure{false};
Ed Tanous7045c8d2017-04-03 10:04:37 -070021
Ed Tanous1abe55e2018-09-05 08:30:59 -070022 const std::string& body;
Ed Tanouse0d918b2018-03-27 17:41:04 -070023
Ed Tanous1abe55e2018-09-05 08:30:59 -070024 void* middlewareContext{};
Ed Tanous8f626352018-12-19 14:51:54 -080025 boost::asio::io_context* ioService{};
Ed Tanous7045c8d2017-04-03 10:04:37 -070026
Ratan Gupta6f359562019-04-03 10:39:08 +053027 std::shared_ptr<crow::persistent_data::UserSession> session;
28
Ed Tanous271584a2019-07-09 16:24:22 -070029 Request(
30 boost::beast::http::request<boost::beast::http::string_body>& reqIn) :
31 req(reqIn),
32 body(reqIn.body())
Ed Tanous1abe55e2018-09-05 08:30:59 -070033 {
34 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070035
Ed Tanous271584a2019-07-09 16:24:22 -070036 boost::beast::http::verb method() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070037 {
38 return req.method();
39 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070040
Ed Tanous39e77502019-03-04 17:35:53 -080041 const std::string_view getHeaderValue(std::string_view key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070042 {
43 return req[key];
44 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070045
Ed Tanous39e77502019-03-04 17:35:53 -080046 const std::string_view getHeaderValue(boost::beast::http::field key) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070047 {
48 return req[key];
49 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070050
Ed Tanous39e77502019-03-04 17:35:53 -080051 const std::string_view methodString() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070052 {
53 return req.method_string();
54 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070055
Ed Tanous39e77502019-03-04 17:35:53 -080056 const std::string_view target() const
Ed Tanous1abe55e2018-09-05 08:30:59 -070057 {
58 return req.target();
59 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070060
Ed Tanous1abe55e2018-09-05 08:30:59 -070061 unsigned version()
62 {
63 return req.version();
64 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070065
Ed Tanous1abe55e2018-09-05 08:30:59 -070066 bool isUpgrade()
67 {
68 return boost::beast::websocket::is_upgrade(req);
69 }
Ed Tanouse0d918b2018-03-27 17:41:04 -070070
Ed Tanous1abe55e2018-09-05 08:30:59 -070071 bool keepAlive()
72 {
73 return req.keep_alive();
74 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070075};
Ed Tanouse0d918b2018-03-27 17:41:04 -070076
Ed Tanous1abe55e2018-09-05 08:30:59 -070077} // namespace crow