blob: 1c24c61d611e5033be75806fbba1dfce71b02d6e [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanous7045c8d2017-04-03 10:04:37 -07003#pragma once
Ed Tanous75312982021-02-11 14:26:02 -08004#include "bmcweb_config.h"
Adriana Kobylak0e1cf262019-12-05 13:57:57 -06005
Ed Tanousd093c992023-01-19 19:01:49 -08006#include "async_resp.hpp"
Nan Zhoud055a342022-05-25 01:15:34 +00007#include "authentication.hpp"
Ed Tanoused5f8952023-06-22 14:06:22 -07008#include "complete_response_fields.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08009#include "forward_unauthorized.hpp"
Ed Tanousfca2cbe2021-01-28 14:49:59 -080010#include "http2_connection.hpp"
Ed Tanousb2896142024-01-31 15:25:47 -080011#include "http_body.hpp"
Ed Tanous796ba932020-08-02 04:29:21 +000012#include "http_connect_types.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080013#include "http_request.hpp"
Ed Tanous04e438c2020-10-03 08:06:26 -070014#include "http_response.hpp"
Ed Tanous1abe55e2018-09-05 08:30:59 -070015#include "http_utility.hpp"
Ed Tanous04e438c2020-10-03 08:06:26 -070016#include "logging.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080017#include "mutual_tls.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080018#include "sessions.hpp"
Ed Tanous18f8f602023-07-18 10:07:23 -070019#include "str_utility.hpp"
Ed Tanouscd7dbb32025-02-01 12:37:56 -080020#include "utility.hpp"
Ed Tanous1abe55e2018-09-05 08:30:59 -070021
Ed Tanousd7857202025-01-28 15:32:26 -080022#include <boost/asio/error.hpp>
Ed Tanous3112a142018-11-29 15:45:10 -080023#include <boost/asio/ip/tcp.hpp>
Ed Tanousd43cd0c2020-09-30 20:46:53 -070024#include <boost/asio/ssl/stream.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080025#include <boost/asio/ssl/stream_base.hpp>
26#include <boost/asio/ssl/verify_context.hpp>
Ed Tanous5dfb5b22021-12-03 11:24:53 -080027#include <boost/asio/steady_timer.hpp>
Ed Tanous4fa45df2023-09-01 14:20:50 -070028#include <boost/beast/_experimental/test/stream.hpp>
Ed Tanous4d698612024-02-06 14:57:24 -080029#include <boost/beast/core/buffers_generator.hpp>
Ed Tanous796ba932020-08-02 04:29:21 +000030#include <boost/beast/core/detect_ssl.hpp>
31#include <boost/beast/core/error.hpp>
Ed Tanous3112a142018-11-29 15:45:10 -080032#include <boost/beast/core/flat_static_buffer.hpp>
Myung Baea4326fe2023-01-10 14:29:24 -060033#include <boost/beast/http/error.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080034#include <boost/beast/http/field.hpp>
Ed Tanous4d698612024-02-06 14:57:24 -080035#include <boost/beast/http/message_generator.hpp>
Ed Tanous918ef252022-05-25 10:40:41 -070036#include <boost/beast/http/parser.hpp>
37#include <boost/beast/http/read.hpp>
Ed Tanouscd7dbb32025-02-01 12:37:56 -080038#include <boost/beast/http/rfc7230.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080039#include <boost/beast/http/status.hpp>
40#include <boost/beast/http/verb.hpp>
41#include <boost/none.hpp>
42#include <boost/optional/optional.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050043
Ed Tanousd7857202025-01-28 15:32:26 -080044#include <bit>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050045#include <chrono>
Ed Tanousd7857202025-01-28 15:32:26 -080046#include <cstddef>
47#include <cstdint>
48#include <functional>
Jonathan Doman102a4cd2024-04-15 16:56:23 -070049#include <memory>
Ed Tanousd7857202025-01-28 15:32:26 -080050#include <optional>
51#include <string>
52#include <string_view>
53#include <system_error>
54#include <type_traits>
55#include <utility>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050056
Ed Tanous1abe55e2018-09-05 08:30:59 -070057namespace crow
58{
Ed Tanous257f5792018-03-17 14:40:09 -070059
Ed Tanouscf9e4172022-12-21 09:30:16 -080060// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
Ed Tanous6fbdbca2021-12-06 14:36:06 -080061static int connectionCount = 0;
Jennifer Leeacb7cfb2018-06-07 16:08:15 -070062
Ed Tanous25b54db2024-04-17 15:40:31 -070063// request body limit size set by the BMCWEB_HTTP_BODY_LIMIT option
64constexpr uint64_t httpReqBodyLimit = 1024UL * 1024UL * BMCWEB_HTTP_BODY_LIMIT;
Jennifer Leeacb7cfb2018-06-07 16:08:15 -070065
Ed Tanous1d1d7782024-04-09 12:54:08 -070066constexpr uint64_t loggedOutPostBodyLimit = 4096U;
James Feist3909dc82020-04-03 10:58:55 -070067
Ed Tanous1d1d7782024-04-09 12:54:08 -070068constexpr uint32_t httpHeaderLimit = 8192U;
James Feist3909dc82020-04-03 10:58:55 -070069
Ed Tanous52cc1122020-07-18 13:51:21 -070070template <typename Adaptor, typename Handler>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050071class Connection :
Ed Tanous52cc1122020-07-18 13:51:21 -070072 public std::enable_shared_from_this<Connection<Adaptor, Handler>>
Ed Tanous1abe55e2018-09-05 08:30:59 -070073{
Ed Tanous7c8e0642022-02-21 12:11:14 -080074 using self_type = Connection<Adaptor, Handler>;
75
Ed Tanous1abe55e2018-09-05 08:30:59 -070076 public:
Ed Tanous796ba932020-08-02 04:29:21 +000077 Connection(Handler* handlerIn, HttpType httpTypeIn,
78 boost::asio::steady_timer&& timerIn,
Ed Tanous81ce6092020-12-17 16:54:55 +000079 std::function<std::string()>& getCachedDateStrF,
Ed Tanous796ba932020-08-02 04:29:21 +000080 boost::asio::ssl::stream<Adaptor>&& adaptorIn) :
81 httpType(httpTypeIn), adaptor(std::move(adaptorIn)), handler(handlerIn),
Patrick Williamsbd79bce2024-08-16 15:22:20 -040082 timer(std::move(timerIn)), getCachedDateStr(getCachedDateStrF)
Ed Tanous1abe55e2018-09-05 08:30:59 -070083 {
Ed Tanous1d1d7782024-04-09 12:54:08 -070084 initParser();
Kowalski, Kamil55e43f62019-07-10 13:12:57 +020085
Ed Tanous40aa0582021-07-14 13:24:40 -070086 connectionCount++;
Ed Tanous6fbdbca2021-12-06 14:36:06 -080087
Ed Tanous1d1d7782024-04-09 12:54:08 -070088 BMCWEB_LOG_DEBUG("{} Connection created, total {}", logPtr(this),
Ed Tanous62598e32023-07-17 17:06:25 -070089 connectionCount);
Ed Tanous40aa0582021-07-14 13:24:40 -070090 }
91
92 ~Connection()
93 {
Ed Tanous1d1d7782024-04-09 12:54:08 -070094 res.releaseCompleteRequestHandler();
Ed Tanous40aa0582021-07-14 13:24:40 -070095 cancelDeadlineTimer();
Ed Tanous6fbdbca2021-12-06 14:36:06 -080096
Ed Tanous40aa0582021-07-14 13:24:40 -070097 connectionCount--;
Ed Tanous62598e32023-07-17 17:06:25 -070098 BMCWEB_LOG_DEBUG("{} Connection closed, total {}", logPtr(this),
99 connectionCount);
Ed Tanous40aa0582021-07-14 13:24:40 -0700100 }
101
Ed Tanousecd6a3a2022-01-07 09:18:40 -0800102 Connection(const Connection&) = delete;
103 Connection(Connection&&) = delete;
104 Connection& operator=(const Connection&) = delete;
105 Connection& operator=(Connection&&) = delete;
106
Ed Tanous7c8e0642022-02-21 12:11:14 -0800107 bool tlsVerifyCallback(bool preverified,
108 boost::asio::ssl::verify_context& ctx)
109 {
Ed Tanous3281bcf2024-06-25 16:02:05 -0700110 BMCWEB_LOG_DEBUG("{} tlsVerifyCallback called with preverified {}",
111 logPtr(this), preverified);
Ed Tanous7c8e0642022-02-21 12:11:14 -0800112 if (preverified)
113 {
Ed Tanous1d1d7782024-04-09 12:54:08 -0700114 mtlsSession = verifyMtlsUser(ip, ctx);
Boleslaw Ogonczyk Makowskib4963072023-02-06 09:59:58 +0100115 if (mtlsSession)
Ed Tanous7c8e0642022-02-21 12:11:14 -0800116 {
Ed Tanous3281bcf2024-06-25 16:02:05 -0700117 BMCWEB_LOG_DEBUG("{} Generated TLS session: {}", logPtr(this),
Ed Tanous62598e32023-07-17 17:06:25 -0700118 mtlsSession->uniqueId);
Ed Tanous7c8e0642022-02-21 12:11:14 -0800119 }
120 }
Ed Tanous3281bcf2024-06-25 16:02:05 -0700121 const persistent_data::AuthConfigMethods& c =
122 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
123 if (c.tlsStrict)
124 {
Ed Tanous463a0e32024-10-14 11:21:48 -0700125 BMCWEB_LOG_DEBUG(
126 "{} TLS is in strict mode, returning preverified as is.",
127 logPtr(this));
Ed Tanous3281bcf2024-06-25 16:02:05 -0700128 return preverified;
129 }
130 // If tls strict mode is disabled
131 // We always return true to allow full auth flow for resources that
132 // don't require auth
Ed Tanous7c8e0642022-02-21 12:11:14 -0800133 return true;
134 }
135
Ed Tanous3281bcf2024-06-25 16:02:05 -0700136 bool prepareMutualTls()
Ed Tanous40aa0582021-07-14 13:24:40 -0700137 {
Ed Tanous796ba932020-08-02 04:29:21 +0000138 BMCWEB_LOG_DEBUG("prepareMutualTls");
139
140 constexpr std::string_view id = "bmcweb";
141
142 const char* idPtr = id.data();
143 const auto* idCPtr = std::bit_cast<const unsigned char*>(idPtr);
144 auto idLen = static_cast<unsigned int>(id.length());
145 int ret =
146 SSL_set_session_id_context(adaptor.native_handle(), idCPtr, idLen);
147 if (ret == 0)
Zbigniew Kurzynski009c2a42019-11-14 13:37:15 +0100148 {
Ed Tanous796ba932020-08-02 04:29:21 +0000149 BMCWEB_LOG_ERROR("{} failed to set SSL id", logPtr(this));
150 return false;
151 }
Zbigniew Kurzynski009c2a42019-11-14 13:37:15 +0100152
Ed Tanous796ba932020-08-02 04:29:21 +0000153 BMCWEB_LOG_DEBUG("set_verify_callback");
Ed Tanous3281bcf2024-06-25 16:02:05 -0700154
Ed Tanous796ba932020-08-02 04:29:21 +0000155 boost::system::error_code ec;
156 adaptor.set_verify_callback(
157 std::bind_front(&self_type::tlsVerifyCallback, this), ec);
158 if (ec)
159 {
160 BMCWEB_LOG_ERROR("Failed to set verify callback {}", ec);
161 return false;
Ed Tanous3281bcf2024-06-25 16:02:05 -0700162 }
163
164 return true;
Ed Tanous7045c8d2017-04-03 10:04:37 -0700165 }
166
Ed Tanous796ba932020-08-02 04:29:21 +0000167 void afterDetectSsl(const std::shared_ptr<self_type>& /*self*/,
168 boost::beast::error_code ec, bool isTls)
169 {
170 if (ec)
171 {
172 BMCWEB_LOG_ERROR("Couldn't detect ssl ", ec);
173 return;
174 }
175 BMCWEB_LOG_DEBUG("{} TLS was detected as {}", logPtr(this), isTls);
176 if (isTls)
177 {
178 if (httpType != HttpType::HTTPS && httpType != HttpType::BOTH)
179 {
180 BMCWEB_LOG_WARNING(
181 "{} Connection closed due to incompatible type",
182 logPtr(this));
183 return;
184 }
185 httpType = HttpType::HTTPS;
186 adaptor.async_handshake(
187 boost::asio::ssl::stream_base::server, buffer.data(),
188 std::bind_front(&self_type::afterSslHandshake, this,
189 shared_from_this()));
190 }
191 else
192 {
193 if (httpType != HttpType::HTTP && httpType != HttpType::BOTH)
194 {
195 BMCWEB_LOG_WARNING(
196 "{} Connection closed due to incompatible type",
197 logPtr(this));
198 return;
199 }
200
201 httpType = HttpType::HTTP;
202 BMCWEB_LOG_INFO("Starting non-SSL session");
203 doReadHeaders();
204 }
205 }
206
Ed Tanous1abe55e2018-09-05 08:30:59 -0700207 void start()
208 {
Ed Tanous1d1d7782024-04-09 12:54:08 -0700209 BMCWEB_LOG_DEBUG("{} Connection started, total {}", logPtr(this),
210 connectionCount);
Gunnar Mills4f63be02023-10-25 09:14:07 -0500211 if (connectionCount >= 200)
Ed Tanous6fbdbca2021-12-06 14:36:06 -0800212 {
Ed Tanous1d1d7782024-04-09 12:54:08 -0700213 BMCWEB_LOG_CRITICAL("{} Max connection count exceeded.",
Ed Tanous62598e32023-07-17 17:06:25 -0700214 logPtr(this));
Ed Tanous6fbdbca2021-12-06 14:36:06 -0800215 return;
216 }
217
Ed Tanous3281bcf2024-06-25 16:02:05 -0700218 if constexpr (BMCWEB_MUTUAL_TLS_AUTH)
219 {
220 if (!prepareMutualTls())
221 {
222 BMCWEB_LOG_ERROR("{} Failed to prepare mTLS", logPtr(this));
223 return;
224 }
225 }
226
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800227 startDeadline();
Sunitha Harishc0ea7ae2020-10-30 02:37:30 -0500228
Ed Tanous1d1d7782024-04-09 12:54:08 -0700229 readClientIp();
Ed Tanous796ba932020-08-02 04:29:21 +0000230 boost::beast::async_detect_ssl(
231 adaptor.next_layer(), buffer,
232 std::bind_front(&self_type::afterDetectSsl, this,
233 shared_from_this()));
Ed Tanous7045c8d2017-04-03 10:04:37 -0700234 }
Ed Tanous7045c8d2017-04-03 10:04:37 -0700235
Ed Tanous796ba932020-08-02 04:29:21 +0000236 void afterSslHandshake(const std::shared_ptr<self_type>& /*self*/,
237 const boost::system::error_code& ec,
238 size_t bytesParsed)
Ed Tanousfca2cbe2021-01-28 14:49:59 -0800239 {
Ed Tanous796ba932020-08-02 04:29:21 +0000240 buffer.consume(bytesParsed);
241 if (ec)
242 {
243 BMCWEB_LOG_ERROR("{} SSL handshake failed", logPtr(this));
244 return;
245 }
246 BMCWEB_LOG_DEBUG("{} SSL handshake succeeded", logPtr(this));
Ed Tanousfca2cbe2021-01-28 14:49:59 -0800247 // If http2 is enabled, negotiate the protocol
Ed Tanous25b54db2024-04-17 15:40:31 -0700248 if constexpr (BMCWEB_EXPERIMENTAL_HTTP2)
Ed Tanousfca2cbe2021-01-28 14:49:59 -0800249 {
250 const unsigned char* alpn = nullptr;
251 unsigned int alpnlen = 0;
252 SSL_get0_alpn_selected(adaptor.native_handle(), &alpn, &alpnlen);
253 if (alpn != nullptr)
254 {
255 std::string_view selectedProtocol(
256 std::bit_cast<const char*>(alpn), alpnlen);
Ed Tanous62598e32023-07-17 17:06:25 -0700257 BMCWEB_LOG_DEBUG("ALPN selected protocol \"{}\" len: {}",
258 selectedProtocol, alpnlen);
Ed Tanousfca2cbe2021-01-28 14:49:59 -0800259 if (selectedProtocol == "h2")
260 {
Ed Tanous796ba932020-08-02 04:29:21 +0000261 upgradeToHttp2();
Ed Tanousfca2cbe2021-01-28 14:49:59 -0800262 return;
263 }
264 }
265 }
266
267 doReadHeaders();
268 }
269
Ed Tanous1d1d7782024-04-09 12:54:08 -0700270 void initParser()
271 {
272 boost::beast::http::request_parser<bmcweb::HttpBody>& instance =
Ed Tanous38afdb92024-12-11 23:57:53 -0800273 parser.emplace();
Ed Tanous1d1d7782024-04-09 12:54:08 -0700274
275 // reset header limit for newly created parser
276 instance.header_limit(httpHeaderLimit);
277
278 // Initially set no body limit. We don't yet know if the user is
279 // authenticated.
280 instance.body_limit(boost::none);
281 }
282
Ed Tanous796ba932020-08-02 04:29:21 +0000283 void upgradeToHttp2()
284 {
Ed Tanousebe4c572025-02-08 14:29:53 -0800285 auto http2 = std::make_shared<HTTP2Connection<Adaptor, Handler>>(
286 std::move(adaptor), handler, getCachedDateStr, httpType);
287 if (http2settings.empty())
Ed Tanous796ba932020-08-02 04:29:21 +0000288 {
Ed Tanousebe4c572025-02-08 14:29:53 -0800289 http2->start();
Ed Tanous796ba932020-08-02 04:29:21 +0000290 }
291 else
292 {
Ed Tanousebe4c572025-02-08 14:29:53 -0800293 http2->startFromSettings(http2settings);
Ed Tanous796ba932020-08-02 04:29:21 +0000294 }
295 }
296
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800297 // returns whether connection was upgraded
298 bool doUpgrade(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
299 {
300 using boost::beast::http::field;
301 using boost::beast::http::token_list;
302
303 bool isSse =
304 isContentTypeAllowed(req->getHeaderValue("Accept"),
305 http_helpers::ContentType::EventStream, false);
306
307 bool isWebsocket = false;
308 bool isH2c = false;
309 // Check connection header is upgrade
310 if (token_list{req->req[field::connection]}.exists("upgrade"))
311 {
312 BMCWEB_LOG_DEBUG("{} Connection: Upgrade header was present",
313 logPtr(this));
314 // Parse if upgrade is h2c or websocket
315 token_list upgrade{req->req[field::upgrade]};
316 isWebsocket = upgrade.exists("websocket");
317 isH2c = upgrade.exists("h2c");
318 BMCWEB_LOG_DEBUG("{} Upgrade isWebsocket: {} isH2c: {}",
319 logPtr(this), isWebsocket, isH2c);
320 }
321
322 if (BMCWEB_EXPERIMENTAL_HTTP2 && isH2c)
323 {
324 std::string_view base64settings = req->req[field::http2_settings];
325 if (utility::base64Decode<true>(base64settings, http2settings))
326 {
327 res.result(boost::beast::http::status::switching_protocols);
328 res.addHeader(boost::beast::http::field::connection, "Upgrade");
329 res.addHeader(boost::beast::http::field::upgrade, "h2c");
330 }
331 }
332
333 // websocket and SSE are only allowed on GET
334 if (req->req.method() == boost::beast::http::verb::get)
335 {
336 if (isWebsocket || isSse)
337 {
338 asyncResp->res.setCompleteRequestHandler(
339 [self(shared_from_this())](crow::Response& thisRes) {
340 if (thisRes.result() != boost::beast::http::status::ok)
341 {
342 // When any error occurs before handle upgradation,
343 // the result in response will be set to respective
344 // error. By default the Result will be OK (200),
345 // which implies successful handle upgrade. Response
346 // needs to be sent over this connection only on
347 // failure.
348 self->completeRequest(thisRes);
349 return;
350 }
351 });
352 BMCWEB_LOG_INFO("{} Upgrading socket", logPtr(this));
Ed Tanous796ba932020-08-02 04:29:21 +0000353 if (httpType == HttpType::HTTP)
354 {
355 handler->handleUpgrade(req, asyncResp,
356 std::move(adaptor.next_layer()));
357 }
358 else
359 {
360 handler->handleUpgrade(req, asyncResp, std::move(adaptor));
361 }
362
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800363 return true;
364 }
365 }
366 return false;
367 }
368
Ed Tanous1abe55e2018-09-05 08:30:59 -0700369 void handle()
370 {
Ed Tanousf79b7a52021-09-22 19:04:29 -0700371 std::error_code reqEc;
Ed Tanouse01d0c32023-06-30 13:21:32 -0700372 if (!parser)
373 {
374 return;
375 }
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700376 req = std::make_shared<crow::Request>(parser->release(), reqEc);
Ed Tanousf79b7a52021-09-22 19:04:29 -0700377 if (reqEc)
378 {
Ed Tanous62598e32023-07-17 17:06:25 -0700379 BMCWEB_LOG_DEBUG("Request failed to construct{}", reqEc.message());
Gunnar Mills262f1152022-12-20 15:18:47 -0600380 res.result(boost::beast::http::status::bad_request);
381 completeRequest(res);
Ed Tanousf79b7a52021-09-22 19:04:29 -0700382 return;
383 }
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700384 req->session = userSession;
Ed Tanous89cda632024-04-16 08:45:54 -0700385 accept = req->getHeaderValue("Accept");
Ivan Mikhaylovf65b0be2021-04-19 10:05:30 +0000386 // Fetch the client IP address
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700387 req->ipAddress = ip;
Ivan Mikhaylovf65b0be2021-04-19 10:05:30 +0000388
Ed Tanous1abe55e2018-09-05 08:30:59 -0700389 // Check for HTTP version 1.1.
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700390 if (req->version() == 11)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700391 {
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700392 if (req->getHeaderValue(boost::beast::http::field::host).empty())
Ed Tanous1abe55e2018-09-05 08:30:59 -0700393 {
Ed Tanousde5c9f32019-03-26 09:17:55 -0700394 res.result(boost::beast::http::status::bad_request);
Nan Zhou72374eb2022-01-27 17:06:51 -0800395 completeRequest(res);
Ed Tanous6c7f01d2021-08-25 13:42:35 -0700396 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700397 }
398 }
Ed Tanous7045c8d2017-04-03 10:04:37 -0700399
Ed Tanous62598e32023-07-17 17:06:25 -0700400 BMCWEB_LOG_INFO("Request: {} HTTP/{}.{} {} {} {}", logPtr(this),
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700401 req->version() / 10, req->version() % 10,
402 req->methodString(), req->target(),
403 req->ipAddress.to_string());
Ed Tanousd32c4fa2021-09-14 13:16:51 -0700404
Ed Tanous6c7f01d2021-08-25 13:42:35 -0700405 if (res.completed)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700406 {
Nan Zhou72374eb2022-01-27 17:06:51 -0800407 completeRequest(res);
Ed Tanous6c7f01d2021-08-25 13:42:35 -0700408 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700409 }
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700410 keepAlive = req->keepAlive();
Ed Tanous796ba932020-08-02 04:29:21 +0000411
412 if (authenticationEnabled)
Ed Tanous1d3c14a2021-09-22 18:54:40 -0700413 {
Ed Tanous796ba932020-08-02 04:29:21 +0000414 if (!crow::authentication::isOnAllowlist(req->url().path(),
415 req->method()) &&
416 req->session == nullptr)
Ed Tanous4fa45df2023-09-01 14:20:50 -0700417 {
Ed Tanous796ba932020-08-02 04:29:21 +0000418 BMCWEB_LOG_WARNING("Authentication failed");
419 forward_unauthorized::sendUnauthorized(
420 req->url().encoded_path(),
421 req->getHeaderValue("X-Requested-With"),
422 req->getHeaderValue("Accept"), res);
423 completeRequest(res);
424 return;
Ed Tanous4fa45df2023-09-01 14:20:50 -0700425 }
Ed Tanous4fa45df2023-09-01 14:20:50 -0700426 }
Ed Tanous796ba932020-08-02 04:29:21 +0000427
Nan Zhou72374eb2022-01-27 17:06:51 -0800428 auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
Ed Tanous62598e32023-07-17 17:06:25 -0700429 BMCWEB_LOG_DEBUG("Setting completion handler");
Nan Zhou72374eb2022-01-27 17:06:51 -0800430 asyncResp->res.setCompleteRequestHandler(
431 [self(shared_from_this())](crow::Response& thisRes) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400432 self->completeRequest(thisRes);
433 });
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800434 if (doUpgrade(asyncResp))
Ed Tanous6c7f01d2021-08-25 13:42:35 -0700435 {
Ed Tanous6c7f01d2021-08-25 13:42:35 -0700436 return;
437 }
Ed Tanous291d7092022-04-13 12:34:57 -0700438 std::string_view expected =
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700439 req->getHeaderValue(boost::beast::http::field::if_none_match);
Ed Tanous291d7092022-04-13 12:34:57 -0700440 if (!expected.empty())
441 {
442 res.setExpectedHash(expected);
443 }
Ed Tanous52e31622024-01-23 16:31:11 -0800444 handler->handle(req, asyncResp);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700445 }
Ed Tanouse0d918b2018-03-27 17:41:04 -0700446
Ed Tanous1d1d7782024-04-09 12:54:08 -0700447 void hardClose()
Ed Tanouse278c182019-03-13 16:23:37 -0700448 {
Ed Tanous1d1d7782024-04-09 12:54:08 -0700449 BMCWEB_LOG_DEBUG("{} Closing socket", logPtr(this));
Ed Tanous796ba932020-08-02 04:29:21 +0000450 adaptor.next_layer().close();
Ed Tanous1d1d7782024-04-09 12:54:08 -0700451 }
452
453 void tlsShutdownComplete(const std::shared_ptr<self_type>& self,
454 const boost::system::error_code& ec)
455 {
456 if (ec)
457 {
458 BMCWEB_LOG_WARNING("{} Failed to shut down TLS cleanly {}",
459 logPtr(self.get()), ec);
460 }
461 self->hardClose();
462 }
463
464 void gracefulClose()
465 {
466 BMCWEB_LOG_DEBUG("{} Socket close requested", logPtr(this));
Ed Tanous3281bcf2024-06-25 16:02:05 -0700467
Ed Tanous796ba932020-08-02 04:29:21 +0000468 if (httpType == HttpType::HTTPS)
Ed Tanouse278c182019-03-13 16:23:37 -0700469 {
Ed Tanous796ba932020-08-02 04:29:21 +0000470 if (mtlsSession != nullptr)
471 {
472 BMCWEB_LOG_DEBUG("{} Removing TLS session: {}", logPtr(this),
473 mtlsSession->uniqueId);
474 persistent_data::SessionStore::getInstance().removeSession(
475 mtlsSession);
476 }
477
Ed Tanous1d1d7782024-04-09 12:54:08 -0700478 adaptor.async_shutdown(std::bind_front(
479 &self_type::tlsShutdownComplete, this, shared_from_this()));
Ed Tanouse278c182019-03-13 16:23:37 -0700480 }
481 else
482 {
Ed Tanous1d1d7782024-04-09 12:54:08 -0700483 hardClose();
Ed Tanouse278c182019-03-13 16:23:37 -0700484 }
485 }
486
Nan Zhou72374eb2022-01-27 17:06:51 -0800487 void completeRequest(crow::Response& thisRes)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700488 {
Nan Zhou72374eb2022-01-27 17:06:51 -0800489 res = std::move(thisRes);
Ed Tanous4cdc2e82023-01-13 10:03:22 -0800490 res.keepAlive(keepAlive);
Ed Tanous5ae6f922023-01-09 10:45:53 -0800491
Ed Tanous89cda632024-04-16 08:45:54 -0700492 completeResponseFields(accept, res);
Ed Tanous998e0cb2023-09-06 13:57:30 -0700493 res.addHeader(boost::beast::http::field::date, getCachedDateStr());
Ed Tanous291d7092022-04-13 12:34:57 -0700494
Ed Tanous52e31622024-01-23 16:31:11 -0800495 doWrite();
Jan Sowinskiee52ae12020-01-09 16:28:32 +0000496
497 // delete lambda with self shared_ptr
498 // to enable connection destruction
John Edward Broadbent4147b8a2021-07-19 16:52:24 -0700499 res.setCompleteRequestHandler(nullptr);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700500 }
501
Sunitha Harishc0ea7ae2020-10-30 02:37:30 -0500502 void readClientIp()
503 {
504 boost::system::error_code ec;
Sunitha Harishc0ea7ae2020-10-30 02:37:30 -0500505
Ed Tanous796ba932020-08-02 04:29:21 +0000506 boost::asio::ip::tcp::endpoint endpoint =
507 boost::beast::get_lowest_layer(adaptor).remote_endpoint(ec);
Ed Tanous4fa45df2023-09-01 14:20:50 -0700508
Ed Tanous796ba932020-08-02 04:29:21 +0000509 if (ec)
510 {
511 // If remote endpoint fails keep going. "ClientOriginIPAddress"
512 // will be empty.
513 BMCWEB_LOG_ERROR("Failed to get the client's IP Address. ec : {}",
514 ec);
515 return;
Sunitha Harishc0ea7ae2020-10-30 02:37:30 -0500516 }
Ed Tanous796ba932020-08-02 04:29:21 +0000517 ip = endpoint.address();
518 }
519
520 void disableAuth()
521 {
522 authenticationEnabled = false;
Sunitha Harishc0ea7ae2020-10-30 02:37:30 -0500523 }
524
Ed Tanous1abe55e2018-09-05 08:30:59 -0700525 private:
Ed Tanous1d1d7782024-04-09 12:54:08 -0700526 uint64_t getContentLengthLimit()
527 {
Ed Tanous83328312024-05-09 15:48:09 -0700528 if constexpr (!BMCWEB_INSECURE_DISABLE_AUTH)
Ed Tanous1d1d7782024-04-09 12:54:08 -0700529 {
Ed Tanous83328312024-05-09 15:48:09 -0700530 if (userSession == nullptr)
531 {
532 return loggedOutPostBodyLimit;
533 }
Ed Tanous1d1d7782024-04-09 12:54:08 -0700534 }
Ed Tanous1d1d7782024-04-09 12:54:08 -0700535
536 return httpReqBodyLimit;
537 }
538
539 // Returns true if content length was within limits
540 // Returns false if content length error has been returned
541 bool handleContentLengthError()
542 {
543 if (!parser)
544 {
Manojkiran Edaefff2b52024-06-18 18:01:46 +0530545 BMCWEB_LOG_CRITICAL("Parser was null");
Ed Tanous1d1d7782024-04-09 12:54:08 -0700546 return false;
547 }
548 const boost::optional<uint64_t> contentLength =
549 parser->content_length();
550 if (!contentLength)
551 {
552 BMCWEB_LOG_DEBUG("{} No content length available", logPtr(this));
553 return true;
554 }
555
556 uint64_t maxAllowedContentLength = getContentLengthLimit();
557
558 if (*contentLength > maxAllowedContentLength)
559 {
560 // If the users content limit is between the logged in
561 // and logged out limits They probably just didn't log
562 // in
563 if (*contentLength > loggedOutPostBodyLimit &&
564 *contentLength < httpReqBodyLimit)
565 {
566 BMCWEB_LOG_DEBUG(
567 "{} Content length {} valid, but greater than logged out"
568 " limit of {}. Setting unauthorized",
569 logPtr(this), *contentLength, loggedOutPostBodyLimit);
570 res.result(boost::beast::http::status::unauthorized);
571 }
572 else
573 {
574 // Otherwise they're over both limits, so inform
575 // them
576 BMCWEB_LOG_DEBUG(
577 "{} Content length {} was greater than global limit {}."
578 " Setting payload too large",
579 logPtr(this), *contentLength, httpReqBodyLimit);
580 res.result(boost::beast::http::status::payload_too_large);
581 }
582
583 keepAlive = false;
584 doWrite();
585 return false;
586 }
587
588 return true;
589 }
590
Ed Tanous116370d2024-10-08 10:37:28 -0700591 void afterReadHeaders(const std::shared_ptr<self_type>& /*self*/,
592 const boost::system::error_code& ec,
593 std::size_t bytesTransferred)
594 {
595 BMCWEB_LOG_DEBUG("{} async_read_header {} Bytes", logPtr(this),
596 bytesTransferred);
597
598 if (ec)
599 {
600 cancelDeadlineTimer();
601
602 if (ec == boost::beast::http::error::header_limit)
603 {
604 BMCWEB_LOG_ERROR("{} Header field too large, closing",
605 logPtr(this), ec.message());
606
607 res.result(boost::beast::http::status::
608 request_header_fields_too_large);
609 keepAlive = false;
610 doWrite();
611 return;
612 }
613 if (ec == boost::beast::http::error::end_of_stream)
614 {
615 BMCWEB_LOG_WARNING("{} End of stream, closing {}", logPtr(this),
616 ec);
617 hardClose();
618 return;
619 }
620
621 BMCWEB_LOG_DEBUG("{} Closing socket due to read error {}",
622 logPtr(this), ec.message());
623 gracefulClose();
624
625 return;
626 }
627
628 if (!parser)
629 {
630 BMCWEB_LOG_ERROR("Parser was unexpectedly null");
631 return;
632 }
633
Ed Tanous796ba932020-08-02 04:29:21 +0000634 if (authenticationEnabled)
Ed Tanous116370d2024-10-08 10:37:28 -0700635 {
636 boost::beast::http::verb method = parser->get().method();
Ed Tanous796ba932020-08-02 04:29:21 +0000637 userSession = authentication::authenticate(
Ed Tanous116370d2024-10-08 10:37:28 -0700638 ip, res, method, parser->get().base(), mtlsSession);
639 }
640
641 std::string_view expect =
642 parser->get()[boost::beast::http::field::expect];
643 if (bmcweb::asciiIEquals(expect, "100-continue"))
644 {
645 res.result(boost::beast::http::status::continue_);
646 doWrite();
647 return;
648 }
649
650 if (!handleContentLengthError())
651 {
652 return;
653 }
654
655 parser->body_limit(getContentLengthLimit());
656
657 if (parser->is_done())
658 {
659 handle();
660 return;
661 }
662
663 doRead();
664 }
665
Ed Tanous1abe55e2018-09-05 08:30:59 -0700666 void doReadHeaders()
667 {
Ed Tanous62598e32023-07-17 17:06:25 -0700668 BMCWEB_LOG_DEBUG("{} doReadHeaders", logPtr(this));
Ed Tanouse01d0c32023-06-30 13:21:32 -0700669 if (!parser)
670 {
Ed Tanous1d1d7782024-04-09 12:54:08 -0700671 BMCWEB_LOG_CRITICAL("Parser was not initialized.");
Ed Tanouse01d0c32023-06-30 13:21:32 -0700672 return;
673 }
Ed Tanous796ba932020-08-02 04:29:21 +0000674
675 if (httpType == HttpType::HTTP)
676 {
677 boost::beast::http::async_read_header(
678 adaptor.next_layer(), buffer, *parser,
679 std::bind_front(&self_type::afterReadHeaders, this,
680 shared_from_this()));
681 }
682 else
683 {
684 boost::beast::http::async_read_header(
685 adaptor, buffer, *parser,
686 std::bind_front(&self_type::afterReadHeaders, this,
687 shared_from_this()));
688 }
Ed Tanous116370d2024-10-08 10:37:28 -0700689 }
Ed Tanous52e31622024-01-23 16:31:11 -0800690
Ed Tanous116370d2024-10-08 10:37:28 -0700691 void afterRead(const std::shared_ptr<self_type>& /*self*/,
692 const boost::system::error_code& ec,
693 std::size_t bytesTransferred)
694 {
695 BMCWEB_LOG_DEBUG("{} async_read_some {} Bytes", logPtr(this),
696 bytesTransferred);
697
698 if (ec)
699 {
700 BMCWEB_LOG_ERROR("{} Error while reading: {}", logPtr(this),
701 ec.message());
702 if (ec == boost::beast::http::error::body_limit)
703 {
704 if (handleContentLengthError())
Ed Tanous1d1d7782024-04-09 12:54:08 -0700705 {
Ed Tanous116370d2024-10-08 10:37:28 -0700706 BMCWEB_LOG_CRITICAL("Body length limit reached, "
707 "but no content-length "
708 "available? Should never happen");
709 res.result(
710 boost::beast::http::status::internal_server_error);
711 keepAlive = false;
Ed Tanous1d1d7782024-04-09 12:54:08 -0700712 doWrite();
Ed Tanous1d1d7782024-04-09 12:54:08 -0700713 }
Ed Tanous116370d2024-10-08 10:37:28 -0700714 return;
715 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400716
Ed Tanous116370d2024-10-08 10:37:28 -0700717 gracefulClose();
718 return;
719 }
Ed Tanous1d1d7782024-04-09 12:54:08 -0700720
Ed Tanous116370d2024-10-08 10:37:28 -0700721 // If the user is logged in, allow them to send files
722 // incrementally one piece at a time. If authentication is
723 // disabled then there is no user session hence always allow to
724 // send one piece at a time.
725 if (userSession != nullptr)
726 {
727 cancelDeadlineTimer();
728 }
Ed Tanous1d1d7782024-04-09 12:54:08 -0700729
Ed Tanous116370d2024-10-08 10:37:28 -0700730 if (!parser)
731 {
732 BMCWEB_LOG_ERROR("Parser was unexpectedly null");
733 return;
734 }
735 if (!parser->is_done())
736 {
737 doRead();
738 return;
739 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700740
Ed Tanous116370d2024-10-08 10:37:28 -0700741 cancelDeadlineTimer();
742 handle();
Ed Tanous1abe55e2018-09-05 08:30:59 -0700743 }
744
745 void doRead()
746 {
Ed Tanous62598e32023-07-17 17:06:25 -0700747 BMCWEB_LOG_DEBUG("{} doRead", logPtr(this));
Ed Tanouse01d0c32023-06-30 13:21:32 -0700748 if (!parser)
749 {
750 return;
751 }
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800752 startDeadline();
Ed Tanous796ba932020-08-02 04:29:21 +0000753 if (httpType == HttpType::HTTP)
754 {
755 boost::beast::http::async_read_some(
756 adaptor.next_layer(), buffer, *parser,
757 std::bind_front(&self_type::afterRead, this,
758 shared_from_this()));
759 }
760 else
761 {
762 boost::beast::http::async_read_some(
763 adaptor, buffer, *parser,
764 std::bind_front(&self_type::afterRead, this,
765 shared_from_this()));
766 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700767 }
768
Ed Tanous27b0cf92023-08-07 12:02:40 -0700769 void afterDoWrite(const std::shared_ptr<self_type>& /*self*/,
770 const boost::system::error_code& ec,
771 std::size_t bytesTransferred)
772 {
Ed Tanous0242baf2024-05-16 19:52:47 -0700773 BMCWEB_LOG_DEBUG("{} async_write wrote {} bytes, ec={}", logPtr(this),
Ed Tanous1d1d7782024-04-09 12:54:08 -0700774 bytesTransferred, ec);
Ed Tanous27b0cf92023-08-07 12:02:40 -0700775
776 cancelDeadlineTimer();
777
Ed Tanous0242baf2024-05-16 19:52:47 -0700778 if (ec == boost::system::errc::operation_would_block ||
779 ec == boost::system::errc::resource_unavailable_try_again)
780 {
781 doWrite();
782 return;
783 }
Ed Tanous27b0cf92023-08-07 12:02:40 -0700784 if (ec)
785 {
786 BMCWEB_LOG_DEBUG("{} from write(2)", logPtr(this));
787 return;
788 }
Ed Tanous1d1d7782024-04-09 12:54:08 -0700789
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800790 if (res.result() == boost::beast::http::status::switching_protocols)
791 {
Ed Tanous796ba932020-08-02 04:29:21 +0000792 upgradeToHttp2();
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800793 return;
794 }
795
Ed Tanous1d1d7782024-04-09 12:54:08 -0700796 if (res.result() == boost::beast::http::status::continue_)
797 {
798 // Reset the result to ok
799 res.result(boost::beast::http::status::ok);
800 doRead();
801 return;
802 }
803
Ed Tanous27b0cf92023-08-07 12:02:40 -0700804 if (!keepAlive)
805 {
Ed Tanous1d1d7782024-04-09 12:54:08 -0700806 BMCWEB_LOG_DEBUG("{} keepalive not set. Closing socket",
807 logPtr(this));
808
809 gracefulClose();
Ed Tanous27b0cf92023-08-07 12:02:40 -0700810 return;
811 }
812
813 BMCWEB_LOG_DEBUG("{} Clearing response", logPtr(this));
814 res.clear();
Ed Tanous1d1d7782024-04-09 12:54:08 -0700815 initParser();
Ed Tanous27b0cf92023-08-07 12:02:40 -0700816
817 userSession = nullptr;
818
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700819 req->clear();
Ed Tanous27b0cf92023-08-07 12:02:40 -0700820 doReadHeaders();
821 }
822
Ed Tanous52e31622024-01-23 16:31:11 -0800823 void doWrite()
Ed Tanous1abe55e2018-09-05 08:30:59 -0700824 {
Ed Tanous62598e32023-07-17 17:06:25 -0700825 BMCWEB_LOG_DEBUG("{} doWrite", logPtr(this));
Ed Tanous52e31622024-01-23 16:31:11 -0800826 res.preparePayload();
Ed Tanous27b0cf92023-08-07 12:02:40 -0700827
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800828 startDeadline();
Ed Tanous796ba932020-08-02 04:29:21 +0000829 if (httpType == HttpType::HTTP)
830 {
831 boost::beast::async_write(
832 adaptor.next_layer(),
833 boost::beast::http::message_generator(std::move(res.response)),
834 std::bind_front(&self_type::afterDoWrite, this,
835 shared_from_this()));
836 }
837 else
838 {
839 boost::beast::async_write(
840 adaptor,
841 boost::beast::http::message_generator(std::move(res.response)),
842 std::bind_front(&self_type::afterDoWrite, this,
843 shared_from_this()));
844 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700845 }
846
Ed Tanous1abe55e2018-09-05 08:30:59 -0700847 void cancelDeadlineTimer()
848 {
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800849 timer.cancel();
Ed Tanous1abe55e2018-09-05 08:30:59 -0700850 }
851
Ed Tanous116370d2024-10-08 10:37:28 -0700852 void afterTimerWait(const std::weak_ptr<self_type>& weakSelf,
853 const boost::system::error_code& ec)
854 {
855 // Note, we are ignoring other types of errors here; If the timer
856 // failed for any reason, we should still close the connection
857 std::shared_ptr<Connection<Adaptor, Handler>> self = weakSelf.lock();
858 if (!self)
859 {
860 if (ec == boost::asio::error::operation_aborted)
861 {
862 BMCWEB_LOG_DEBUG(
863 "{} Timer canceled on connection being destroyed",
864 logPtr(self.get()));
865 }
866 else
867 {
868 BMCWEB_LOG_CRITICAL("{} Failed to capture connection",
869 logPtr(self.get()));
870 }
871 return;
872 }
873
874 self->timerStarted = false;
875
876 if (ec)
877 {
878 if (ec == boost::asio::error::operation_aborted)
879 {
880 BMCWEB_LOG_DEBUG("{} Timer canceled", logPtr(self.get()));
881 return;
882 }
883 BMCWEB_LOG_CRITICAL("{} Timer failed {}", logPtr(self.get()), ec);
884 }
885
886 BMCWEB_LOG_WARNING("{} Connection timed out, hard closing",
887 logPtr(self.get()));
888
889 self->hardClose();
890 }
891
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800892 void startDeadline()
Ed Tanous1abe55e2018-09-05 08:30:59 -0700893 {
Ed Tanous7d243eb2023-01-23 15:57:41 -0800894 // Timer is already started so no further action is required.
895 if (timerStarted)
896 {
897 return;
898 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700899
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800900 std::chrono::seconds timeout(15);
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800901
902 std::weak_ptr<Connection<Adaptor, Handler>> weakSelf = weak_from_this();
903 timer.expires_after(timeout);
Ed Tanous116370d2024-10-08 10:37:28 -0700904 timer.async_wait(std::bind_front(&self_type::afterTimerWait, this,
905 weak_from_this()));
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800906
Ed Tanous7d243eb2023-01-23 15:57:41 -0800907 timerStarted = true;
Ed Tanous62598e32023-07-17 17:06:25 -0700908 BMCWEB_LOG_DEBUG("{} timer started", logPtr(this));
Ed Tanous1abe55e2018-09-05 08:30:59 -0700909 }
910
Ed Tanous796ba932020-08-02 04:29:21 +0000911 bool authenticationEnabled = !BMCWEB_INSECURE_DISABLE_AUTH;
912 HttpType httpType = HttpType::BOTH;
913
914 boost::asio::ssl::stream<Adaptor> adaptor;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700915 Handler* handler;
Ed Tanous1d1d7782024-04-09 12:54:08 -0700916
917 boost::asio::ip::address ip;
918
Ed Tanousa24526d2018-12-10 15:17:59 -0800919 // Making this a std::optional allows it to be efficiently destroyed and
Ed Tanous1abe55e2018-09-05 08:30:59 -0700920 // re-created on Connection reset
Ed Tanousb2896142024-01-31 15:25:47 -0800921 std::optional<boost::beast::http::request_parser<bmcweb::HttpBody>> parser;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700922
Ed Tanous3112a142018-11-29 15:45:10 -0800923 boost::beast::flat_static_buffer<8192> buffer;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700924
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700925 std::shared_ptr<crow::Request> req;
Ed Tanous89cda632024-04-16 08:45:54 -0700926 std::string accept;
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800927 std::string http2settings;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700928 crow::Response res;
Ed Tanous52cc1122020-07-18 13:51:21 -0700929
John Edward Broadbent59b98b22021-07-13 15:36:32 -0700930 std::shared_ptr<persistent_data::UserSession> userSession;
Boleslaw Ogonczyk Makowskib4963072023-02-06 09:59:58 +0100931 std::shared_ptr<persistent_data::UserSession> mtlsSession;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700932
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800933 boost::asio::steady_timer timer;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700934
Ed Tanous4cdc2e82023-01-13 10:03:22 -0800935 bool keepAlive = true;
936
Ed Tanous7d243eb2023-01-23 15:57:41 -0800937 bool timerStarted = false;
938
Ed Tanous1abe55e2018-09-05 08:30:59 -0700939 std::function<std::string()>& getCachedDateStr;
Jan Sowinskiee52ae12020-01-09 16:28:32 +0000940
941 using std::enable_shared_from_this<
Ed Tanous52cc1122020-07-18 13:51:21 -0700942 Connection<Adaptor, Handler>>::shared_from_this;
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800943
944 using std::enable_shared_from_this<
945 Connection<Adaptor, Handler>>::weak_from_this;
Ed Tanous3112a142018-11-29 15:45:10 -0800946};
Ed Tanous1abe55e2018-09-05 08:30:59 -0700947} // namespace crow