2014-03-31 16:51:50 +00:00
|
|
|
#pragma once
|
|
|
|
#include <boost/asio.hpp>
|
2014-04-01 12:25:16 +00:00
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
2014-08-06 23:31:27 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2014-09-06 19:30:53 +00:00
|
|
|
#include <boost/array.hpp>
|
2014-05-02 05:17:49 +00:00
|
|
|
#include <atomic>
|
|
|
|
#include <chrono>
|
2014-10-23 17:45:34 +00:00
|
|
|
#include <vector>
|
2014-07-29 11:20:50 +00:00
|
|
|
|
2016-09-21 14:11:06 +00:00
|
|
|
#include "crow/http_parser_merged.h"
|
2014-04-01 12:25:16 +00:00
|
|
|
|
2016-09-21 14:11:06 +00:00
|
|
|
#include "crow/parser.h"
|
|
|
|
#include "crow/http_response.h"
|
|
|
|
#include "crow/logging.h"
|
|
|
|
#include "crow/settings.h"
|
|
|
|
#include "crow/dumb_timer_queue.h"
|
|
|
|
#include "crow/middleware_context.h"
|
|
|
|
#include "crow/socket_adaptors.h"
|
2021-01-02 19:12:04 +00:00
|
|
|
#include "crow/compression.h"
|
2014-03-31 16:51:50 +00:00
|
|
|
|
2014-04-26 17:19:59 +00:00
|
|
|
namespace crow
|
2014-03-31 16:51:50 +00:00
|
|
|
{
|
2015-09-20 13:06:00 +00:00
|
|
|
using namespace boost;
|
|
|
|
using tcp = asio::ip::tcp;
|
|
|
|
|
2014-09-06 19:30:53 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
2015-02-20 01:53:43 +00:00
|
|
|
template <typename MW>
|
|
|
|
struct check_before_handle_arity_3_const
|
|
|
|
{
|
|
|
|
template <typename T,
|
|
|
|
void (T::*)(request&, response&, typename MW::context&) const = &T::before_handle
|
|
|
|
>
|
|
|
|
struct get
|
|
|
|
{ };
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename MW>
|
|
|
|
struct check_before_handle_arity_3
|
|
|
|
{
|
|
|
|
template <typename T,
|
|
|
|
void (T::*)(request&, response&, typename MW::context&) = &T::before_handle
|
|
|
|
>
|
|
|
|
struct get
|
|
|
|
{ };
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename MW>
|
|
|
|
struct check_after_handle_arity_3_const
|
|
|
|
{
|
|
|
|
template <typename T,
|
|
|
|
void (T::*)(request&, response&, typename MW::context&) const = &T::after_handle
|
|
|
|
>
|
|
|
|
struct get
|
|
|
|
{ };
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename MW>
|
|
|
|
struct check_after_handle_arity_3
|
|
|
|
{
|
|
|
|
template <typename T,
|
|
|
|
void (T::*)(request&, response&, typename MW::context&) = &T::after_handle
|
|
|
|
>
|
|
|
|
struct get
|
|
|
|
{ };
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct is_before_handle_arity_3_impl
|
|
|
|
{
|
|
|
|
template <typename C>
|
|
|
|
static std::true_type f(typename check_before_handle_arity_3_const<T>::template get<C>*);
|
|
|
|
|
|
|
|
template <typename C>
|
|
|
|
static std::true_type f(typename check_before_handle_arity_3<T>::template get<C>*);
|
|
|
|
|
|
|
|
template <typename C>
|
|
|
|
static std::false_type f(...);
|
|
|
|
|
|
|
|
public:
|
|
|
|
static const bool value = decltype(f<T>(nullptr))::value;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct is_after_handle_arity_3_impl
|
|
|
|
{
|
|
|
|
template <typename C>
|
|
|
|
static std::true_type f(typename check_after_handle_arity_3_const<T>::template get<C>*);
|
|
|
|
|
|
|
|
template <typename C>
|
|
|
|
static std::true_type f(typename check_after_handle_arity_3<T>::template get<C>*);
|
|
|
|
|
|
|
|
template <typename C>
|
|
|
|
static std::false_type f(...);
|
|
|
|
|
|
|
|
public:
|
|
|
|
static const bool value = decltype(f<T>(nullptr))::value;
|
|
|
|
};
|
|
|
|
|
2014-09-07 22:07:53 +00:00
|
|
|
template <typename MW, typename Context, typename ParentContext>
|
2015-02-20 01:53:43 +00:00
|
|
|
typename std::enable_if<!is_before_handle_arity_3_impl<MW>::value>::type
|
2016-08-27 09:03:49 +00:00
|
|
|
before_handler_call(MW& mw, request& req, response& res, Context& ctx, ParentContext& /*parent_ctx*/)
|
2014-09-07 22:07:53 +00:00
|
|
|
{
|
2015-02-20 01:53:43 +00:00
|
|
|
mw.before_handle(req, res, ctx.template get<MW>(), ctx);
|
2014-09-07 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MW, typename Context, typename ParentContext>
|
2015-02-20 01:53:43 +00:00
|
|
|
typename std::enable_if<is_before_handle_arity_3_impl<MW>::value>::type
|
2016-08-27 09:03:49 +00:00
|
|
|
before_handler_call(MW& mw, request& req, response& res, Context& ctx, ParentContext& /*parent_ctx*/)
|
2014-09-07 22:07:53 +00:00
|
|
|
{
|
2015-02-20 01:53:43 +00:00
|
|
|
mw.before_handle(req, res, ctx.template get<MW>());
|
2014-09-07 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MW, typename Context, typename ParentContext>
|
2015-02-20 01:53:43 +00:00
|
|
|
typename std::enable_if<!is_after_handle_arity_3_impl<MW>::value>::type
|
2016-08-27 09:03:49 +00:00
|
|
|
after_handler_call(MW& mw, request& req, response& res, Context& ctx, ParentContext& /*parent_ctx*/)
|
2014-09-07 22:07:53 +00:00
|
|
|
{
|
2015-02-20 01:53:43 +00:00
|
|
|
mw.after_handle(req, res, ctx.template get<MW>(), ctx);
|
2014-09-07 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename MW, typename Context, typename ParentContext>
|
2015-02-20 01:53:43 +00:00
|
|
|
typename std::enable_if<is_after_handle_arity_3_impl<MW>::value>::type
|
2016-08-27 09:03:49 +00:00
|
|
|
after_handler_call(MW& mw, request& req, response& res, Context& ctx, ParentContext& /*parent_ctx*/)
|
2014-09-07 22:07:53 +00:00
|
|
|
{
|
2015-02-20 01:53:43 +00:00
|
|
|
mw.after_handle(req, res, ctx.template get<MW>());
|
2014-09-07 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
2014-09-06 19:30:53 +00:00
|
|
|
template <int N, typename Context, typename Container, typename CurrentMW, typename ... Middlewares>
|
|
|
|
bool middleware_call_helper(Container& middlewares, request& req, response& res, Context& ctx)
|
|
|
|
{
|
2014-09-07 22:07:53 +00:00
|
|
|
using parent_context_t = typename Context::template partial<N-1>;
|
|
|
|
before_handler_call<CurrentMW, Context, parent_context_t>(std::get<N>(middlewares), req, res, ctx, static_cast<parent_context_t&>(ctx));
|
|
|
|
|
2014-09-06 19:30:53 +00:00
|
|
|
if (res.is_completed())
|
|
|
|
{
|
2014-09-07 22:07:53 +00:00
|
|
|
after_handler_call<CurrentMW, Context, parent_context_t>(std::get<N>(middlewares), req, res, ctx, static_cast<parent_context_t&>(ctx));
|
2014-09-06 19:30:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-09-07 22:07:53 +00:00
|
|
|
|
|
|
|
if (middleware_call_helper<N+1, Context, Container, Middlewares...>(middlewares, req, res, ctx))
|
2014-09-06 19:30:53 +00:00
|
|
|
{
|
2014-09-07 22:07:53 +00:00
|
|
|
after_handler_call<CurrentMW, Context, parent_context_t>(std::get<N>(middlewares), req, res, ctx, static_cast<parent_context_t&>(ctx));
|
2014-09-06 19:30:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-09-07 22:07:53 +00:00
|
|
|
|
2014-09-06 19:30:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <int N, typename Context, typename Container>
|
2016-08-27 09:03:49 +00:00
|
|
|
bool middleware_call_helper(Container& /*middlewares*/, request& /*req*/, response& /*res*/, Context& /*ctx*/)
|
2014-09-06 19:30:53 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-07 22:07:53 +00:00
|
|
|
|
|
|
|
template <int N, typename Context, typename Container>
|
|
|
|
typename std::enable_if<(N<0)>::type
|
2016-08-27 09:03:49 +00:00
|
|
|
after_handlers_call_helper(Container& /*middlewares*/, Context& /*context*/, request& /*req*/, response& /*res*/)
|
2014-09-07 22:07:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <int N, typename Context, typename Container>
|
|
|
|
typename std::enable_if<(N==0)>::type after_handlers_call_helper(Container& middlewares, Context& ctx, request& req, response& res)
|
|
|
|
{
|
|
|
|
using parent_context_t = typename Context::template partial<N-1>;
|
|
|
|
using CurrentMW = typename std::tuple_element<N, typename std::remove_reference<Container>::type>::type;
|
|
|
|
after_handler_call<CurrentMW, Context, parent_context_t>(std::get<N>(middlewares), req, res, ctx, static_cast<parent_context_t&>(ctx));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <int N, typename Context, typename Container>
|
|
|
|
typename std::enable_if<(N>0)>::type after_handlers_call_helper(Container& middlewares, Context& ctx, request& req, response& res)
|
|
|
|
{
|
|
|
|
using parent_context_t = typename Context::template partial<N-1>;
|
|
|
|
using CurrentMW = typename std::tuple_element<N, typename std::remove_reference<Container>::type>::type;
|
|
|
|
after_handler_call<CurrentMW, Context, parent_context_t>(std::get<N>(middlewares), req, res, ctx, static_cast<parent_context_t&>(ctx));
|
|
|
|
after_handlers_call_helper<N-1, Context, Container>(middlewares, ctx, req, res);
|
|
|
|
}
|
2014-09-06 19:30:53 +00:00
|
|
|
}
|
|
|
|
|
2014-07-29 11:20:50 +00:00
|
|
|
#ifdef CROW_ENABLE_DEBUG
|
2016-11-15 15:44:45 +00:00
|
|
|
static std::atomic<int> connectionCount;
|
2014-07-29 11:20:50 +00:00
|
|
|
#endif
|
2020-11-18 22:13:57 +00:00
|
|
|
|
|
|
|
/// An HTTP connection.
|
2015-09-20 13:06:00 +00:00
|
|
|
template <typename Adaptor, typename Handler, typename ... Middlewares>
|
2014-08-15 02:06:00 +00:00
|
|
|
class Connection
|
2014-03-31 16:51:50 +00:00
|
|
|
{
|
2020-10-19 16:55:40 +00:00
|
|
|
friend struct crow::response;
|
2014-03-31 16:51:50 +00:00
|
|
|
public:
|
2014-09-06 19:30:53 +00:00
|
|
|
Connection(
|
|
|
|
boost::asio::io_service& io_service,
|
|
|
|
Handler* handler,
|
|
|
|
const std::string& server_name,
|
2015-02-20 04:44:46 +00:00
|
|
|
std::tuple<Middlewares...>* middlewares,
|
|
|
|
std::function<std::string()>& get_cached_date_str_f,
|
2015-09-20 13:06:00 +00:00
|
|
|
detail::dumb_timer_queue& timer_queue,
|
|
|
|
typename Adaptor::context* adaptor_ctx_
|
2014-09-06 19:30:53 +00:00
|
|
|
)
|
2015-09-20 13:06:00 +00:00
|
|
|
: adaptor_(io_service, adaptor_ctx_),
|
2014-05-02 05:17:49 +00:00
|
|
|
handler_(handler),
|
|
|
|
parser_(this),
|
2014-09-06 19:30:53 +00:00
|
|
|
server_name_(server_name),
|
2015-02-20 04:44:46 +00:00
|
|
|
middlewares_(middlewares),
|
|
|
|
get_cached_date_str(get_cached_date_str_f),
|
|
|
|
timer_queue(timer_queue)
|
2014-07-29 11:20:50 +00:00
|
|
|
{
|
|
|
|
#ifdef CROW_ENABLE_DEBUG
|
|
|
|
connectionCount ++;
|
|
|
|
CROW_LOG_DEBUG << "Connection open, total " << connectionCount << ", " << this;
|
|
|
|
#endif
|
|
|
|
}
|
2014-08-05 18:54:38 +00:00
|
|
|
|
2014-07-29 11:20:50 +00:00
|
|
|
~Connection()
|
2014-03-31 16:51:50 +00:00
|
|
|
{
|
2014-08-05 18:54:38 +00:00
|
|
|
res.complete_request_handler_ = nullptr;
|
2014-08-16 02:55:26 +00:00
|
|
|
cancel_deadline_timer();
|
2014-08-05 18:54:38 +00:00
|
|
|
#ifdef CROW_ENABLE_DEBUG
|
2014-07-29 11:20:50 +00:00
|
|
|
connectionCount --;
|
|
|
|
CROW_LOG_DEBUG << "Connection closed, total " << connectionCount << ", " << this;
|
|
|
|
#endif
|
2014-08-05 18:54:38 +00:00
|
|
|
}
|
2014-03-31 16:51:50 +00:00
|
|
|
|
2020-11-18 22:13:57 +00:00
|
|
|
/// The TCP socket on top of which the connection is established.
|
2015-09-20 13:06:00 +00:00
|
|
|
decltype(std::declval<Adaptor>().raw_socket())& socket()
|
2014-08-17 09:35:21 +00:00
|
|
|
{
|
2015-09-20 13:06:00 +00:00
|
|
|
return adaptor_.raw_socket();
|
2014-08-17 09:35:21 +00:00
|
|
|
}
|
|
|
|
|
2014-03-31 16:51:50 +00:00
|
|
|
void start()
|
|
|
|
{
|
2015-09-20 13:06:00 +00:00
|
|
|
adaptor_.start([this](const boost::system::error_code& ec) {
|
|
|
|
if (!ec)
|
|
|
|
{
|
|
|
|
start_deadline();
|
2014-07-29 11:20:50 +00:00
|
|
|
|
2015-09-20 13:06:00 +00:00
|
|
|
do_read();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_destroy();
|
|
|
|
}
|
|
|
|
});
|
2014-03-31 16:51:50 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 12:54:25 +00:00
|
|
|
void handle_header()
|
|
|
|
{
|
|
|
|
// HTTP 1.1 Expect: 100-continue
|
2014-09-10 21:32:41 +00:00
|
|
|
if (parser_.check_version(1, 1) && parser_.headers.count("expect") && get_header_value(parser_.headers, "expect") == "100-continue")
|
2014-05-02 12:54:25 +00:00
|
|
|
{
|
|
|
|
buffers_.clear();
|
|
|
|
static std::string expect_100_continue = "HTTP/1.1 100 Continue\r\n\r\n";
|
|
|
|
buffers_.emplace_back(expect_100_continue.data(), expect_100_continue.size());
|
|
|
|
do_write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 12:25:16 +00:00
|
|
|
void handle()
|
|
|
|
{
|
2014-08-16 16:10:19 +00:00
|
|
|
cancel_deadline_timer();
|
2014-05-02 09:22:02 +00:00
|
|
|
bool is_invalid_request = false;
|
2014-09-19 23:20:35 +00:00
|
|
|
add_keep_alive_ = false;
|
2014-05-02 09:22:02 +00:00
|
|
|
|
2014-09-07 22:07:53 +00:00
|
|
|
req_ = std::move(parser_.to_request());
|
|
|
|
request& req = req_;
|
2016-08-28 05:46:31 +00:00
|
|
|
|
2021-08-14 13:28:23 +00:00
|
|
|
req.remote_ip_address = adaptor_.remote_endpoint().address().to_string();
|
2018-09-28 19:13:52 +00:00
|
|
|
|
2014-05-02 12:54:25 +00:00
|
|
|
if (parser_.check_version(1, 0))
|
2014-04-20 08:45:10 +00:00
|
|
|
{
|
|
|
|
// HTTP/1.0
|
2014-09-19 23:20:35 +00:00
|
|
|
if (req.headers.count("connection"))
|
|
|
|
{
|
|
|
|
if (boost::iequals(req.get_header_value("connection"),"Keep-Alive"))
|
|
|
|
add_keep_alive_ = true;
|
|
|
|
}
|
2014-09-19 21:28:36 +00:00
|
|
|
else
|
2014-09-19 23:20:35 +00:00
|
|
|
close_connection_ = true;
|
2014-04-20 08:45:10 +00:00
|
|
|
}
|
2014-05-02 12:54:25 +00:00
|
|
|
else if (parser_.check_version(1, 1))
|
2014-04-20 08:45:10 +00:00
|
|
|
{
|
|
|
|
// HTTP/1.1
|
2014-09-19 23:20:35 +00:00
|
|
|
if (req.headers.count("connection"))
|
|
|
|
{
|
|
|
|
if (req.get_header_value("connection") == "close")
|
|
|
|
close_connection_ = true;
|
|
|
|
else if (boost::iequals(req.get_header_value("connection"),"Keep-Alive"))
|
|
|
|
add_keep_alive_ = true;
|
|
|
|
}
|
2014-05-02 09:22:02 +00:00
|
|
|
if (!req.headers.count("host"))
|
|
|
|
{
|
|
|
|
is_invalid_request = true;
|
|
|
|
res = response(400);
|
|
|
|
}
|
2016-08-28 05:46:31 +00:00
|
|
|
if (parser_.is_upgrade())
|
|
|
|
{
|
|
|
|
if (req.get_header_value("upgrade") == "h2c")
|
|
|
|
{
|
|
|
|
// TODO HTTP/2
|
|
|
|
// currently, ignore upgrade header
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
close_connection_ = true;
|
|
|
|
handler_->handle_upgrade(req, res, std::move(adaptor_));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-04-20 08:45:10 +00:00
|
|
|
}
|
|
|
|
|
2015-09-20 13:06:00 +00:00
|
|
|
CROW_LOG_INFO << "Request: " << boost::lexical_cast<std::string>(adaptor_.remote_endpoint()) << " " << this << " HTTP/" << parser_.http_major << "." << parser_.http_minor << ' '
|
2014-08-05 18:54:38 +00:00
|
|
|
<< method_name(req.method) << " " << req.url;
|
|
|
|
|
|
|
|
|
2014-09-06 19:30:53 +00:00
|
|
|
need_to_call_after_handlers_ = false;
|
2014-05-02 09:22:02 +00:00
|
|
|
if (!is_invalid_request)
|
|
|
|
{
|
2014-09-07 22:07:53 +00:00
|
|
|
res.complete_request_handler_ = []{};
|
2015-09-20 13:06:00 +00:00
|
|
|
res.is_alive_helper_ = [this]()->bool{ return adaptor_.is_open(); };
|
2014-09-06 19:30:53 +00:00
|
|
|
|
2014-09-07 22:07:53 +00:00
|
|
|
ctx_ = detail::context<Middlewares...>();
|
2021-02-21 00:14:30 +00:00
|
|
|
req.middleware_context = static_cast<void*>(&ctx_);
|
2016-08-28 05:46:31 +00:00
|
|
|
req.io_service = &adaptor_.get_io_service();
|
2014-10-23 17:33:03 +00:00
|
|
|
detail::middleware_call_helper<0, decltype(ctx_), decltype(*middlewares_), Middlewares...>(*middlewares_, req, res, ctx_);
|
2014-09-06 19:30:53 +00:00
|
|
|
|
|
|
|
if (!res.completed_)
|
|
|
|
{
|
2014-09-07 22:07:53 +00:00
|
|
|
res.complete_request_handler_ = [this]{ this->complete_request(); };
|
2014-09-06 19:30:53 +00:00
|
|
|
need_to_call_after_handlers_ = true;
|
|
|
|
handler_->handle(req, res);
|
2014-09-19 23:20:35 +00:00
|
|
|
if (add_keep_alive_)
|
|
|
|
res.set_header("connection", "Keep-Alive");
|
2014-09-06 19:30:53 +00:00
|
|
|
}
|
2014-09-07 22:07:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
complete_request();
|
|
|
|
}
|
2014-05-02 09:22:02 +00:00
|
|
|
}
|
2014-09-19 23:20:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
complete_request();
|
|
|
|
}
|
2014-08-05 18:54:38 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 22:13:57 +00:00
|
|
|
/// Call the after handle middleware and send the write the response to the connection.
|
2014-08-05 18:54:38 +00:00
|
|
|
void complete_request()
|
|
|
|
{
|
2014-10-14 08:48:35 +00:00
|
|
|
CROW_LOG_INFO << "Response: " << this << ' ' << req_.raw_url << ' ' << res.code << ' ' << close_connection_;
|
2014-08-05 18:54:38 +00:00
|
|
|
|
2014-09-06 19:30:53 +00:00
|
|
|
if (need_to_call_after_handlers_)
|
|
|
|
{
|
2014-09-14 11:12:18 +00:00
|
|
|
need_to_call_after_handlers_ = false;
|
|
|
|
|
2014-09-07 22:07:53 +00:00
|
|
|
// call all after_handler of middlewares
|
|
|
|
detail::after_handlers_call_helper<
|
2021-02-21 00:14:30 +00:00
|
|
|
(static_cast<int>(sizeof...(Middlewares))-1),
|
2014-09-07 22:07:53 +00:00
|
|
|
decltype(ctx_),
|
2020-10-04 12:05:26 +00:00
|
|
|
decltype(*middlewares_)>
|
2014-10-23 17:33:03 +00:00
|
|
|
(*middlewares_, ctx_, req_, res);
|
2014-09-06 19:30:53 +00:00
|
|
|
}
|
2021-06-03 14:12:20 +00:00
|
|
|
#ifdef CROW_ENABLE_COMPRESSION
|
2021-01-02 19:12:04 +00:00
|
|
|
std::string accept_encoding = req_.get_header_value("Accept-Encoding");
|
|
|
|
if (!accept_encoding.empty() && res.compressed)
|
|
|
|
{
|
|
|
|
switch (handler_->compression_algorithm())
|
|
|
|
{
|
|
|
|
case compression::DEFLATE:
|
|
|
|
if (accept_encoding.find("deflate") != std::string::npos)
|
|
|
|
{
|
|
|
|
res.body = compression::compress_string(res.body, compression::algorithm::DEFLATE);
|
|
|
|
res.set_header("Content-Encoding", "deflate");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case compression::GZIP:
|
|
|
|
if (accept_encoding.find("gzip") != std::string::npos)
|
|
|
|
{
|
|
|
|
res.body = compression::compress_string(res.body, compression::algorithm::GZIP);
|
|
|
|
res.set_header("Content-Encoding", "gzip");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-01-21 18:36:41 +00:00
|
|
|
}
|
2021-06-03 14:12:20 +00:00
|
|
|
#endif
|
2020-12-26 16:54:41 +00:00
|
|
|
//if there is a redirection with a partial URL, treat the URL as a route.
|
|
|
|
std::string location = res.get_header_value("Location");
|
2021-01-03 14:56:19 +00:00
|
|
|
if (!location.empty() && location.find("://", 0) == std::string::npos)
|
2020-12-26 16:54:41 +00:00
|
|
|
{
|
|
|
|
#ifdef CROW_ENABLE_SSL
|
|
|
|
location.insert(0, "https://" + req_.get_header_value("Host"));
|
|
|
|
#else
|
|
|
|
location.insert(0, "http://" + req_.get_header_value("Host"));
|
|
|
|
#endif
|
|
|
|
res.set_header("location", location);
|
2021-01-02 19:12:04 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 12:05:26 +00:00
|
|
|
prepare_buffers();
|
2021-04-12 17:11:03 +00:00
|
|
|
|
2020-11-14 02:28:07 +00:00
|
|
|
if (res.is_static_type())
|
2020-10-04 12:05:26 +00:00
|
|
|
{
|
|
|
|
do_write_static();
|
|
|
|
}else {
|
|
|
|
do_write_general();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-09-06 19:30:53 +00:00
|
|
|
|
2020-10-21 01:02:09 +00:00
|
|
|
void prepare_buffers()
|
|
|
|
{
|
2014-08-15 02:06:00 +00:00
|
|
|
//auto self = this->shared_from_this();
|
2014-08-05 18:54:38 +00:00
|
|
|
res.complete_request_handler_ = nullptr;
|
2020-10-04 12:05:26 +00:00
|
|
|
|
2015-09-20 13:06:00 +00:00
|
|
|
if (!adaptor_.is_open())
|
2014-08-15 02:06:00 +00:00
|
|
|
{
|
2014-08-16 16:10:19 +00:00
|
|
|
//CROW_LOG_DEBUG << this << " delete (socket is closed) " << is_reading << ' ' << is_writing;
|
|
|
|
//delete this;
|
2014-09-19 23:20:35 +00:00
|
|
|
return;
|
2014-08-15 02:06:00 +00:00
|
|
|
}
|
2014-08-05 18:54:38 +00:00
|
|
|
|
|
|
|
static std::unordered_map<int, std::string> statusCodes = {
|
2021-09-29 17:30:59 +00:00
|
|
|
{100, "HTTP/1.1 100 Continue\r\n"},
|
|
|
|
{101, "HTTP/1.1 101 Switching Protocols\r\n"},
|
|
|
|
{102, "HTTP/1.1 102 Processing\r\n"},
|
|
|
|
{103, "HTTP/1.1 103 Early Hints\r\n"},
|
|
|
|
|
2014-08-05 18:54:38 +00:00
|
|
|
{200, "HTTP/1.1 200 OK\r\n"},
|
|
|
|
{201, "HTTP/1.1 201 Created\r\n"},
|
|
|
|
{202, "HTTP/1.1 202 Accepted\r\n"},
|
2021-09-29 17:30:59 +00:00
|
|
|
{203, "HTTP/1.1 203 Non-Authoritative Information\r\n"},
|
2014-08-05 18:54:38 +00:00
|
|
|
{204, "HTTP/1.1 204 No Content\r\n"},
|
2021-09-29 17:30:59 +00:00
|
|
|
{205, "HTTP/1.1 205 Reset Content\r\n"},
|
|
|
|
{206, "HTTP/1.1 206 Partial Content\r\n"},
|
|
|
|
{207, "HTTP/1.1 207 Multi-Status\r\n"},
|
|
|
|
{208, "HTTP/1.1 208 Already Reported\r\n"},
|
|
|
|
{226, "HTTP/1.1 226 IM Used\r\n"},
|
2014-04-01 12:25:16 +00:00
|
|
|
|
2014-08-05 18:54:38 +00:00
|
|
|
{300, "HTTP/1.1 300 Multiple Choices\r\n"},
|
|
|
|
{301, "HTTP/1.1 301 Moved Permanently\r\n"},
|
2020-12-26 16:54:41 +00:00
|
|
|
{302, "HTTP/1.1 302 Found\r\n"},
|
|
|
|
{303, "HTTP/1.1 303 See Other\r\n"},
|
2014-08-05 18:54:38 +00:00
|
|
|
{304, "HTTP/1.1 304 Not Modified\r\n"},
|
2021-09-29 17:30:59 +00:00
|
|
|
{305, "HTTP/1.1 305 Use Proxy\r\n"},
|
|
|
|
{306, "HTTP/1.1 306 Switch Proxy\r\n"},
|
2020-12-26 16:54:41 +00:00
|
|
|
{307, "HTTP/1.1 307 Temporary Redirect\r\n"},
|
|
|
|
{308, "HTTP/1.1 308 Permanent Redirect\r\n"},
|
2014-08-05 18:54:38 +00:00
|
|
|
|
|
|
|
{400, "HTTP/1.1 400 Bad Request\r\n"},
|
|
|
|
{401, "HTTP/1.1 401 Unauthorized\r\n"},
|
2021-09-29 17:30:59 +00:00
|
|
|
{402, "HTTP/1.1 402 Payment Required\r\n"},
|
2014-08-05 18:54:38 +00:00
|
|
|
{403, "HTTP/1.1 403 Forbidden\r\n"},
|
|
|
|
{404, "HTTP/1.1 404 Not Found\r\n"},
|
2020-10-14 21:09:17 +00:00
|
|
|
{405, "HTTP/1.1 405 Method Not Allowed\r\n"},
|
2021-09-29 17:30:59 +00:00
|
|
|
{406, "HTTP/1.1 406 Not Acceptable\r\n"},
|
|
|
|
{407, "HTTP/1.1 407 Proxy Authentication Required\r\n"},
|
|
|
|
{408, "HTTP/1.1 408 Request Timeout\r\n"},
|
|
|
|
{409, "HTTP/1.1 409 Conflict\r\n"},
|
|
|
|
{410, "HTTP/1.1 410 Gone\r\n"},
|
|
|
|
{411, "HTTP/1.1 411 Length Required\r\n"},
|
|
|
|
{412, "HTTP/1.1 412 Precondition Failed\r\n"},
|
2017-10-20 13:20:18 +00:00
|
|
|
{413, "HTTP/1.1 413 Payload Too Large\r\n"},
|
2021-09-29 17:30:59 +00:00
|
|
|
{414, "HTTP/1.1 414 URI Too Long\r\n"},
|
|
|
|
{415, "HTTP/1.1 415 Unsupported Media Type\r\n"},
|
|
|
|
{416, "HTTP/1.1 416 Range Not Satisfiable\r\n"},
|
|
|
|
{417, "HTTP/1.1 417 Expectation Failed\r\n"},
|
|
|
|
{418, "HTTP/1.1 418 I'm a teapot\r\n"},
|
|
|
|
{421, "HTTP/1.1 421 Misdirected Request\r\n"},
|
2017-09-04 15:40:40 +00:00
|
|
|
{422, "HTTP/1.1 422 Unprocessable Entity\r\n"},
|
2021-09-29 17:30:59 +00:00
|
|
|
{423, "HTTP/1.1 423 Locked\r\n"},
|
|
|
|
{424, "HTTP/1.1 424 Failed Dependency\r\n"},
|
|
|
|
{425, "HTTP/1.1 425 Too Early\r\n"},
|
|
|
|
{426, "HTTP/1.1 426 Upgrade Required\r\n"},
|
|
|
|
{428, "HTTP/1.1 428 Precondition Required\r\n"},
|
2017-10-20 13:20:18 +00:00
|
|
|
{429, "HTTP/1.1 429 Too Many Requests\r\n"},
|
2021-09-29 17:30:59 +00:00
|
|
|
{431, "HTTP/1.1 431 Request Header Fields Too Large\r\n"},
|
|
|
|
{451, "HTTP/1.1 451 Unavailable For Legal Reasons\r\n"},
|
2014-08-05 18:54:38 +00:00
|
|
|
|
|
|
|
{500, "HTTP/1.1 500 Internal Server Error\r\n"},
|
|
|
|
{501, "HTTP/1.1 501 Not Implemented\r\n"},
|
|
|
|
{502, "HTTP/1.1 502 Bad Gateway\r\n"},
|
|
|
|
{503, "HTTP/1.1 503 Service Unavailable\r\n"},
|
2021-09-29 17:30:59 +00:00
|
|
|
{504, "HTTP/1.1 504 Gateway Timeout\r\n"},
|
|
|
|
{505, "HTTP/1.1 505 HTTP Version Not Supported\r\n"},
|
|
|
|
{506, "HTTP/1.1 506 Variant Also Negotiates\r\n"},
|
|
|
|
{507, "HTTP/1.1 507 Insufficient Storage\r\n"},
|
|
|
|
{508, "HTTP/1.1 508 Loop Detected\r\n"},
|
|
|
|
{510, "HTTP/1.1 510 Not Extended\r\n"},
|
|
|
|
{511, "HTTP/1.1 511 Network Authentication Required\r\n"},
|
2014-08-05 18:54:38 +00:00
|
|
|
};
|
2014-04-20 08:45:10 +00:00
|
|
|
|
2014-04-01 12:25:16 +00:00
|
|
|
static std::string seperator = ": ";
|
|
|
|
static std::string crlf = "\r\n";
|
|
|
|
|
2014-04-17 06:50:28 +00:00
|
|
|
buffers_.clear();
|
2014-09-19 23:20:35 +00:00
|
|
|
buffers_.reserve(4*(res.headers.size()+5)+3);
|
2014-04-01 12:25:16 +00:00
|
|
|
|
2014-04-17 06:50:28 +00:00
|
|
|
if (!statusCodes.count(res.code))
|
|
|
|
res.code = 500;
|
|
|
|
{
|
|
|
|
auto& status = statusCodes.find(res.code)->second;
|
|
|
|
buffers_.emplace_back(status.data(), status.size());
|
|
|
|
}
|
2014-04-14 20:11:37 +00:00
|
|
|
|
2014-04-17 09:18:02 +00:00
|
|
|
if (res.code >= 400 && res.body.empty())
|
2014-04-14 20:11:37 +00:00
|
|
|
res.body = statusCodes[res.code].substr(9);
|
2014-04-01 12:25:16 +00:00
|
|
|
|
|
|
|
for(auto& kv : res.headers)
|
|
|
|
{
|
2014-04-17 06:50:28 +00:00
|
|
|
buffers_.emplace_back(kv.first.data(), kv.first.size());
|
|
|
|
buffers_.emplace_back(seperator.data(), seperator.size());
|
|
|
|
buffers_.emplace_back(kv.second.data(), kv.second.size());
|
|
|
|
buffers_.emplace_back(crlf.data(), crlf.size());
|
2014-04-01 12:25:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-03 10:48:36 +00:00
|
|
|
if (!res.manual_length_header && !res.headers.count("content-length"))
|
2014-04-17 06:50:28 +00:00
|
|
|
{
|
2014-08-01 21:30:02 +00:00
|
|
|
content_length_ = std::to_string(res.body.size());
|
2014-05-02 05:17:49 +00:00
|
|
|
static std::string content_length_tag = "Content-Length: ";
|
|
|
|
buffers_.emplace_back(content_length_tag.data(), content_length_tag.size());
|
|
|
|
buffers_.emplace_back(content_length_.data(), content_length_.size());
|
2014-04-17 06:50:28 +00:00
|
|
|
buffers_.emplace_back(crlf.data(), crlf.size());
|
|
|
|
}
|
2014-09-19 23:20:35 +00:00
|
|
|
if (!res.headers.count("server"))
|
2014-04-17 06:50:28 +00:00
|
|
|
{
|
2014-05-02 05:17:49 +00:00
|
|
|
static std::string server_tag = "Server: ";
|
|
|
|
buffers_.emplace_back(server_tag.data(), server_tag.size());
|
|
|
|
buffers_.emplace_back(server_name_.data(), server_name_.size());
|
2014-04-17 06:50:28 +00:00
|
|
|
buffers_.emplace_back(crlf.data(), crlf.size());
|
|
|
|
}
|
2014-09-19 23:20:35 +00:00
|
|
|
if (!res.headers.count("date"))
|
2014-04-17 06:50:28 +00:00
|
|
|
{
|
2014-05-02 05:17:49 +00:00
|
|
|
static std::string date_tag = "Date: ";
|
|
|
|
date_str_ = get_cached_date_str();
|
|
|
|
buffers_.emplace_back(date_tag.data(), date_tag.size());
|
|
|
|
buffers_.emplace_back(date_str_.data(), date_str_.size());
|
2014-04-18 22:27:05 +00:00
|
|
|
buffers_.emplace_back(crlf.data(), crlf.size());
|
2014-04-17 06:50:28 +00:00
|
|
|
}
|
2014-09-19 23:20:35 +00:00
|
|
|
if (add_keep_alive_)
|
|
|
|
{
|
2016-03-07 23:30:19 +00:00
|
|
|
static std::string keep_alive_tag = "Connection: Keep-Alive";
|
2014-09-19 23:20:35 +00:00
|
|
|
buffers_.emplace_back(keep_alive_tag.data(), keep_alive_tag.size());
|
|
|
|
buffers_.emplace_back(crlf.data(), crlf.size());
|
|
|
|
}
|
2014-04-01 12:25:16 +00:00
|
|
|
|
2014-04-17 06:50:28 +00:00
|
|
|
buffers_.emplace_back(crlf.data(), crlf.size());
|
2020-10-04 12:05:26 +00:00
|
|
|
|
|
|
|
}
|
2020-11-12 13:27:26 +00:00
|
|
|
|
2020-10-21 01:02:09 +00:00
|
|
|
void do_write_static()
|
|
|
|
{
|
2020-10-04 12:05:26 +00:00
|
|
|
is_writing = true;
|
|
|
|
boost::asio::write(adaptor_.socket(), buffers_);
|
2020-10-21 01:02:09 +00:00
|
|
|
res.do_stream_file(adaptor_);
|
2020-10-12 21:53:27 +00:00
|
|
|
|
2020-10-04 12:05:26 +00:00
|
|
|
res.end();
|
|
|
|
res.clear();
|
|
|
|
buffers_.clear();
|
|
|
|
}
|
2020-11-12 13:27:26 +00:00
|
|
|
|
2020-10-21 01:02:09 +00:00
|
|
|
void do_write_general()
|
|
|
|
{
|
2020-10-21 17:54:28 +00:00
|
|
|
if (res.body.length() < res_stream_threshold_)
|
2020-10-21 01:02:09 +00:00
|
|
|
{
|
|
|
|
res_body_copy_.swap(res.body);
|
|
|
|
buffers_.emplace_back(res_body_copy_.data(), res_body_copy_.size());
|
2014-04-01 12:25:16 +00:00
|
|
|
|
2020-10-21 01:02:09 +00:00
|
|
|
do_write();
|
2014-09-14 11:12:18 +00:00
|
|
|
|
2020-10-21 01:02:09 +00:00
|
|
|
if (need_to_start_read_after_complete_)
|
|
|
|
{
|
|
|
|
need_to_start_read_after_complete_ = false;
|
|
|
|
start_deadline();
|
|
|
|
do_read();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-09-14 11:12:18 +00:00
|
|
|
{
|
2020-10-21 01:02:09 +00:00
|
|
|
is_writing = true;
|
|
|
|
boost::asio::write(adaptor_.socket(), buffers_);
|
|
|
|
res.do_stream_body(adaptor_);
|
|
|
|
|
|
|
|
res.end();
|
|
|
|
res.clear();
|
|
|
|
buffers_.clear();
|
2014-09-14 11:12:18 +00:00
|
|
|
}
|
2014-04-01 12:25:16 +00:00
|
|
|
}
|
|
|
|
|
2014-03-31 16:51:50 +00:00
|
|
|
void do_read()
|
|
|
|
{
|
2014-08-15 02:06:00 +00:00
|
|
|
//auto self = this->shared_from_this();
|
|
|
|
is_reading = true;
|
2015-09-20 13:06:00 +00:00
|
|
|
adaptor_.socket().async_read_some(boost::asio::buffer(buffer_),
|
2014-08-15 02:06:00 +00:00
|
|
|
[this](const boost::system::error_code& ec, std::size_t bytes_transferred)
|
2014-03-31 16:51:50 +00:00
|
|
|
{
|
2014-07-29 11:20:50 +00:00
|
|
|
bool error_while_reading = true;
|
2014-03-31 16:51:50 +00:00
|
|
|
if (!ec)
|
|
|
|
{
|
2014-04-01 12:25:16 +00:00
|
|
|
bool ret = parser_.feed(buffer_.data(), bytes_transferred);
|
2016-09-09 17:13:50 +00:00
|
|
|
if (ret && adaptor_.is_open())
|
2014-07-29 11:20:50 +00:00
|
|
|
{
|
|
|
|
error_while_reading = false;
|
|
|
|
}
|
2014-04-01 12:25:16 +00:00
|
|
|
}
|
2014-07-29 11:20:50 +00:00
|
|
|
|
|
|
|
if (error_while_reading)
|
2014-04-01 12:25:16 +00:00
|
|
|
{
|
2014-08-16 02:55:26 +00:00
|
|
|
cancel_deadline_timer();
|
2014-04-10 16:43:33 +00:00
|
|
|
parser_.done();
|
2020-10-20 08:48:35 +00:00
|
|
|
adaptor_.shutdown_read();
|
2015-09-20 13:06:00 +00:00
|
|
|
adaptor_.close();
|
2014-08-15 02:06:00 +00:00
|
|
|
is_reading = false;
|
2014-08-16 02:55:26 +00:00
|
|
|
CROW_LOG_DEBUG << this << " from read(1)";
|
2014-08-16 16:10:19 +00:00
|
|
|
check_destroy();
|
2014-07-29 11:20:50 +00:00
|
|
|
}
|
2016-09-09 17:13:50 +00:00
|
|
|
else if (close_connection_)
|
|
|
|
{
|
|
|
|
cancel_deadline_timer();
|
|
|
|
parser_.done();
|
|
|
|
is_reading = false;
|
|
|
|
check_destroy();
|
|
|
|
// adaptor will close after write
|
|
|
|
}
|
2014-09-14 11:12:18 +00:00
|
|
|
else if (!need_to_call_after_handlers_)
|
2014-07-29 11:20:50 +00:00
|
|
|
{
|
|
|
|
start_deadline();
|
2014-08-16 16:10:19 +00:00
|
|
|
do_read();
|
2014-04-01 12:25:16 +00:00
|
|
|
}
|
2014-09-14 11:12:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// res will be completed later by user
|
|
|
|
need_to_start_read_after_complete_ = true;
|
|
|
|
}
|
2014-04-01 12:25:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-04-17 06:50:28 +00:00
|
|
|
void do_write()
|
2014-04-01 12:25:16 +00:00
|
|
|
{
|
2014-08-15 02:06:00 +00:00
|
|
|
//auto self = this->shared_from_this();
|
|
|
|
is_writing = true;
|
2015-09-20 13:06:00 +00:00
|
|
|
boost::asio::async_write(adaptor_.socket(), buffers_,
|
2016-08-27 09:03:49 +00:00
|
|
|
[&](const boost::system::error_code& ec, std::size_t /*bytes_transferred*/)
|
2014-04-01 12:25:16 +00:00
|
|
|
{
|
2014-08-15 02:06:00 +00:00
|
|
|
is_writing = false;
|
2016-03-07 23:22:35 +00:00
|
|
|
res.clear();
|
2015-09-20 13:06:00 +00:00
|
|
|
res_body_copy_.clear();
|
2014-04-01 12:25:16 +00:00
|
|
|
if (!ec)
|
|
|
|
{
|
|
|
|
if (close_connection_)
|
|
|
|
{
|
2020-10-20 08:48:35 +00:00
|
|
|
adaptor_.shutdown_write();
|
2015-09-20 13:06:00 +00:00
|
|
|
adaptor_.close();
|
2014-08-16 02:55:26 +00:00
|
|
|
CROW_LOG_DEBUG << this << " from write(1)";
|
2014-08-16 16:10:19 +00:00
|
|
|
check_destroy();
|
2014-04-01 12:25:16 +00:00
|
|
|
}
|
2014-03-31 16:51:50 +00:00
|
|
|
}
|
2014-08-15 02:06:00 +00:00
|
|
|
else
|
2014-08-16 02:55:26 +00:00
|
|
|
{
|
|
|
|
CROW_LOG_DEBUG << this << " from write(2)";
|
2014-08-16 16:10:19 +00:00
|
|
|
check_destroy();
|
2014-08-16 02:55:26 +00:00
|
|
|
}
|
2014-03-31 16:51:50 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-08-16 16:10:19 +00:00
|
|
|
void check_destroy()
|
2014-08-15 02:06:00 +00:00
|
|
|
{
|
2014-08-16 02:55:26 +00:00
|
|
|
CROW_LOG_DEBUG << this << " is_reading " << is_reading << " is_writing " << is_writing;
|
2014-08-15 02:06:00 +00:00
|
|
|
if (!is_reading && !is_writing)
|
|
|
|
{
|
|
|
|
CROW_LOG_DEBUG << this << " delete (idle) ";
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-16 02:55:26 +00:00
|
|
|
void cancel_deadline_timer()
|
|
|
|
{
|
2014-08-16 16:10:19 +00:00
|
|
|
CROW_LOG_DEBUG << this << " timer cancelled: " << timer_cancel_key_.first << ' ' << timer_cancel_key_.second;
|
2015-02-20 04:44:46 +00:00
|
|
|
timer_queue.cancel(timer_cancel_key_);
|
2014-08-16 02:55:26 +00:00
|
|
|
}
|
|
|
|
|
2016-08-27 09:03:49 +00:00
|
|
|
void start_deadline(/*int timeout = 5*/)
|
2014-07-29 11:20:50 +00:00
|
|
|
{
|
2014-08-16 02:55:26 +00:00
|
|
|
cancel_deadline_timer();
|
|
|
|
|
2014-08-16 16:10:19 +00:00
|
|
|
timer_cancel_key_ = timer_queue.add([this]
|
2014-07-29 11:20:50 +00:00
|
|
|
{
|
2015-09-20 13:06:00 +00:00
|
|
|
if (!adaptor_.is_open())
|
2014-07-29 11:20:50 +00:00
|
|
|
{
|
2014-08-16 02:55:26 +00:00
|
|
|
return;
|
2014-07-29 11:20:50 +00:00
|
|
|
}
|
2020-10-20 08:48:35 +00:00
|
|
|
adaptor_.shutdown_readwrite();
|
2015-09-20 13:06:00 +00:00
|
|
|
adaptor_.close();
|
2014-07-29 11:20:50 +00:00
|
|
|
});
|
2014-08-16 16:10:19 +00:00
|
|
|
CROW_LOG_DEBUG << this << " timer added: " << timer_cancel_key_.first << ' ' << timer_cancel_key_.second;
|
2014-07-29 11:20:50 +00:00
|
|
|
}
|
|
|
|
|
2014-03-31 16:51:50 +00:00
|
|
|
private:
|
2015-09-20 13:06:00 +00:00
|
|
|
Adaptor adaptor_;
|
2014-03-31 16:51:50 +00:00
|
|
|
Handler* handler_;
|
|
|
|
|
2014-09-06 19:30:53 +00:00
|
|
|
boost::array<char, 4096> buffer_;
|
2014-03-31 16:51:50 +00:00
|
|
|
|
2020-11-12 13:11:22 +00:00
|
|
|
const unsigned res_stream_threshold_ = 1048576;
|
2020-10-21 01:02:09 +00:00
|
|
|
|
2014-04-01 12:25:16 +00:00
|
|
|
HTTPParser<Connection> parser_;
|
2014-09-07 22:07:53 +00:00
|
|
|
request req_;
|
2014-04-01 12:25:16 +00:00
|
|
|
response res;
|
|
|
|
|
|
|
|
bool close_connection_ = false;
|
2014-04-17 06:50:28 +00:00
|
|
|
|
|
|
|
const std::string& server_name_;
|
|
|
|
std::vector<boost::asio::const_buffer> buffers_;
|
2014-05-02 05:17:49 +00:00
|
|
|
|
|
|
|
std::string content_length_;
|
|
|
|
std::string date_str_;
|
2015-09-20 13:06:00 +00:00
|
|
|
std::string res_body_copy_;
|
2014-07-29 11:20:50 +00:00
|
|
|
|
2014-08-16 02:55:26 +00:00
|
|
|
//boost::asio::deadline_timer deadline_;
|
2014-08-16 16:10:19 +00:00
|
|
|
detail::dumb_timer_queue::key timer_cancel_key_;
|
2014-08-15 02:06:00 +00:00
|
|
|
|
|
|
|
bool is_reading{};
|
|
|
|
bool is_writing{};
|
2015-01-19 09:59:55 +00:00
|
|
|
bool need_to_call_after_handlers_{};
|
2014-09-14 11:12:18 +00:00
|
|
|
bool need_to_start_read_after_complete_{};
|
2014-09-19 23:20:35 +00:00
|
|
|
bool add_keep_alive_{};
|
2014-09-06 19:30:53 +00:00
|
|
|
|
2014-10-23 17:33:03 +00:00
|
|
|
std::tuple<Middlewares...>* middlewares_;
|
2014-09-06 19:30:53 +00:00
|
|
|
detail::context<Middlewares...> ctx_;
|
2015-02-20 04:44:46 +00:00
|
|
|
|
|
|
|
std::function<std::string()>& get_cached_date_str;
|
|
|
|
detail::dumb_timer_queue& timer_queue;
|
2014-03-31 16:51:50 +00:00
|
|
|
};
|
2014-07-29 11:20:50 +00:00
|
|
|
|
2014-03-31 16:51:50 +00:00
|
|
|
}
|