blob: c9eb2aeedb07bbe369a88f2dadcc16ebe6eaeac0 [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 {
285 // TODO HTTP2Connection needs adaptor moved to a similar abstraction as
286 // HTTPConnection
287 if (httpType == HttpType::HTTP)
288 {
289 auto http2 = std::make_shared<HTTP2Connection<Adaptor, Handler>>(
290 std::move(adaptor.next_layer()), handler, getCachedDateStr);
291 if (http2settings.empty())
292 {
293 http2->start();
294 }
295 else
296 {
297 http2->startFromSettings(http2settings);
298 }
299 }
300 else
301 {
302 auto http2 = std::make_shared<
303 HTTP2Connection<boost::asio::ssl::stream<Adaptor>, Handler>>(
304 std::move(adaptor), handler, getCachedDateStr);
305 if (http2settings.empty())
306 {
307 http2->start();
308 }
309 else
310 {
311 http2->startFromSettings(http2settings);
312 }
313 }
314 }
315
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800316 // returns whether connection was upgraded
317 bool doUpgrade(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
318 {
319 using boost::beast::http::field;
320 using boost::beast::http::token_list;
321
322 bool isSse =
323 isContentTypeAllowed(req->getHeaderValue("Accept"),
324 http_helpers::ContentType::EventStream, false);
325
326 bool isWebsocket = false;
327 bool isH2c = false;
328 // Check connection header is upgrade
329 if (token_list{req->req[field::connection]}.exists("upgrade"))
330 {
331 BMCWEB_LOG_DEBUG("{} Connection: Upgrade header was present",
332 logPtr(this));
333 // Parse if upgrade is h2c or websocket
334 token_list upgrade{req->req[field::upgrade]};
335 isWebsocket = upgrade.exists("websocket");
336 isH2c = upgrade.exists("h2c");
337 BMCWEB_LOG_DEBUG("{} Upgrade isWebsocket: {} isH2c: {}",
338 logPtr(this), isWebsocket, isH2c);
339 }
340
341 if (BMCWEB_EXPERIMENTAL_HTTP2 && isH2c)
342 {
343 std::string_view base64settings = req->req[field::http2_settings];
344 if (utility::base64Decode<true>(base64settings, http2settings))
345 {
346 res.result(boost::beast::http::status::switching_protocols);
347 res.addHeader(boost::beast::http::field::connection, "Upgrade");
348 res.addHeader(boost::beast::http::field::upgrade, "h2c");
349 }
350 }
351
352 // websocket and SSE are only allowed on GET
353 if (req->req.method() == boost::beast::http::verb::get)
354 {
355 if (isWebsocket || isSse)
356 {
357 asyncResp->res.setCompleteRequestHandler(
358 [self(shared_from_this())](crow::Response& thisRes) {
359 if (thisRes.result() != boost::beast::http::status::ok)
360 {
361 // When any error occurs before handle upgradation,
362 // the result in response will be set to respective
363 // error. By default the Result will be OK (200),
364 // which implies successful handle upgrade. Response
365 // needs to be sent over this connection only on
366 // failure.
367 self->completeRequest(thisRes);
368 return;
369 }
370 });
371 BMCWEB_LOG_INFO("{} Upgrading socket", logPtr(this));
Ed Tanous796ba932020-08-02 04:29:21 +0000372 if (httpType == HttpType::HTTP)
373 {
374 handler->handleUpgrade(req, asyncResp,
375 std::move(adaptor.next_layer()));
376 }
377 else
378 {
379 handler->handleUpgrade(req, asyncResp, std::move(adaptor));
380 }
381
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800382 return true;
383 }
384 }
385 return false;
386 }
387
Ed Tanous1abe55e2018-09-05 08:30:59 -0700388 void handle()
389 {
Ed Tanousf79b7a52021-09-22 19:04:29 -0700390 std::error_code reqEc;
Ed Tanouse01d0c32023-06-30 13:21:32 -0700391 if (!parser)
392 {
393 return;
394 }
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700395 req = std::make_shared<crow::Request>(parser->release(), reqEc);
Ed Tanousf79b7a52021-09-22 19:04:29 -0700396 if (reqEc)
397 {
Ed Tanous62598e32023-07-17 17:06:25 -0700398 BMCWEB_LOG_DEBUG("Request failed to construct{}", reqEc.message());
Gunnar Mills262f1152022-12-20 15:18:47 -0600399 res.result(boost::beast::http::status::bad_request);
400 completeRequest(res);
Ed Tanousf79b7a52021-09-22 19:04:29 -0700401 return;
402 }
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700403 req->session = userSession;
Ed Tanous89cda632024-04-16 08:45:54 -0700404 accept = req->getHeaderValue("Accept");
Ivan Mikhaylovf65b0be2021-04-19 10:05:30 +0000405 // Fetch the client IP address
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700406 req->ipAddress = ip;
Ivan Mikhaylovf65b0be2021-04-19 10:05:30 +0000407
Ed Tanous1abe55e2018-09-05 08:30:59 -0700408 // Check for HTTP version 1.1.
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700409 if (req->version() == 11)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700410 {
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700411 if (req->getHeaderValue(boost::beast::http::field::host).empty())
Ed Tanous1abe55e2018-09-05 08:30:59 -0700412 {
Ed Tanousde5c9f32019-03-26 09:17:55 -0700413 res.result(boost::beast::http::status::bad_request);
Nan Zhou72374eb2022-01-27 17:06:51 -0800414 completeRequest(res);
Ed Tanous6c7f01d2021-08-25 13:42:35 -0700415 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700416 }
417 }
Ed Tanous7045c8d2017-04-03 10:04:37 -0700418
Ed Tanous62598e32023-07-17 17:06:25 -0700419 BMCWEB_LOG_INFO("Request: {} HTTP/{}.{} {} {} {}", logPtr(this),
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700420 req->version() / 10, req->version() % 10,
421 req->methodString(), req->target(),
422 req->ipAddress.to_string());
Ed Tanousd32c4fa2021-09-14 13:16:51 -0700423
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700424 req->ioService = static_cast<decltype(req->ioService)>(
Ed Tanous6c7f01d2021-08-25 13:42:35 -0700425 &adaptor.get_executor().context());
Kowalski, Kamil55e43f62019-07-10 13:12:57 +0200426
Ed Tanous6c7f01d2021-08-25 13:42:35 -0700427 if (res.completed)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700428 {
Nan Zhou72374eb2022-01-27 17:06:51 -0800429 completeRequest(res);
Ed Tanous6c7f01d2021-08-25 13:42:35 -0700430 return;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700431 }
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700432 keepAlive = req->keepAlive();
Ed Tanous796ba932020-08-02 04:29:21 +0000433
434 if (authenticationEnabled)
Ed Tanous1d3c14a2021-09-22 18:54:40 -0700435 {
Ed Tanous796ba932020-08-02 04:29:21 +0000436 if (!crow::authentication::isOnAllowlist(req->url().path(),
437 req->method()) &&
438 req->session == nullptr)
Ed Tanous4fa45df2023-09-01 14:20:50 -0700439 {
Ed Tanous796ba932020-08-02 04:29:21 +0000440 BMCWEB_LOG_WARNING("Authentication failed");
441 forward_unauthorized::sendUnauthorized(
442 req->url().encoded_path(),
443 req->getHeaderValue("X-Requested-With"),
444 req->getHeaderValue("Accept"), res);
445 completeRequest(res);
446 return;
Ed Tanous4fa45df2023-09-01 14:20:50 -0700447 }
Ed Tanous4fa45df2023-09-01 14:20:50 -0700448 }
Ed Tanous796ba932020-08-02 04:29:21 +0000449
Nan Zhou72374eb2022-01-27 17:06:51 -0800450 auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
Ed Tanous62598e32023-07-17 17:06:25 -0700451 BMCWEB_LOG_DEBUG("Setting completion handler");
Nan Zhou72374eb2022-01-27 17:06:51 -0800452 asyncResp->res.setCompleteRequestHandler(
453 [self(shared_from_this())](crow::Response& thisRes) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400454 self->completeRequest(thisRes);
455 });
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800456 if (doUpgrade(asyncResp))
Ed Tanous6c7f01d2021-08-25 13:42:35 -0700457 {
Ed Tanous6c7f01d2021-08-25 13:42:35 -0700458 return;
459 }
Ed Tanous291d7092022-04-13 12:34:57 -0700460 std::string_view expected =
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700461 req->getHeaderValue(boost::beast::http::field::if_none_match);
Ed Tanous291d7092022-04-13 12:34:57 -0700462 if (!expected.empty())
463 {
464 res.setExpectedHash(expected);
465 }
Ed Tanous52e31622024-01-23 16:31:11 -0800466 handler->handle(req, asyncResp);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700467 }
Ed Tanouse0d918b2018-03-27 17:41:04 -0700468
Ed Tanous1d1d7782024-04-09 12:54:08 -0700469 void hardClose()
Ed Tanouse278c182019-03-13 16:23:37 -0700470 {
Ed Tanous1d1d7782024-04-09 12:54:08 -0700471 BMCWEB_LOG_DEBUG("{} Closing socket", logPtr(this));
Ed Tanous796ba932020-08-02 04:29:21 +0000472 adaptor.next_layer().close();
Ed Tanous1d1d7782024-04-09 12:54:08 -0700473 }
474
475 void tlsShutdownComplete(const std::shared_ptr<self_type>& self,
476 const boost::system::error_code& ec)
477 {
478 if (ec)
479 {
480 BMCWEB_LOG_WARNING("{} Failed to shut down TLS cleanly {}",
481 logPtr(self.get()), ec);
482 }
483 self->hardClose();
484 }
485
486 void gracefulClose()
487 {
488 BMCWEB_LOG_DEBUG("{} Socket close requested", logPtr(this));
Ed Tanous3281bcf2024-06-25 16:02:05 -0700489
Ed Tanous796ba932020-08-02 04:29:21 +0000490 if (httpType == HttpType::HTTPS)
Ed Tanouse278c182019-03-13 16:23:37 -0700491 {
Ed Tanous796ba932020-08-02 04:29:21 +0000492 if (mtlsSession != nullptr)
493 {
494 BMCWEB_LOG_DEBUG("{} Removing TLS session: {}", logPtr(this),
495 mtlsSession->uniqueId);
496 persistent_data::SessionStore::getInstance().removeSession(
497 mtlsSession);
498 }
499
Ed Tanous1d1d7782024-04-09 12:54:08 -0700500 adaptor.async_shutdown(std::bind_front(
501 &self_type::tlsShutdownComplete, this, shared_from_this()));
Ed Tanouse278c182019-03-13 16:23:37 -0700502 }
503 else
504 {
Ed Tanous1d1d7782024-04-09 12:54:08 -0700505 hardClose();
Ed Tanouse278c182019-03-13 16:23:37 -0700506 }
507 }
508
Nan Zhou72374eb2022-01-27 17:06:51 -0800509 void completeRequest(crow::Response& thisRes)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700510 {
Nan Zhou72374eb2022-01-27 17:06:51 -0800511 res = std::move(thisRes);
Ed Tanous4cdc2e82023-01-13 10:03:22 -0800512 res.keepAlive(keepAlive);
Ed Tanous5ae6f922023-01-09 10:45:53 -0800513
Ed Tanous89cda632024-04-16 08:45:54 -0700514 completeResponseFields(accept, res);
Ed Tanous998e0cb2023-09-06 13:57:30 -0700515 res.addHeader(boost::beast::http::field::date, getCachedDateStr());
Ed Tanous291d7092022-04-13 12:34:57 -0700516
Ed Tanous52e31622024-01-23 16:31:11 -0800517 doWrite();
Jan Sowinskiee52ae12020-01-09 16:28:32 +0000518
519 // delete lambda with self shared_ptr
520 // to enable connection destruction
John Edward Broadbent4147b8a2021-07-19 16:52:24 -0700521 res.setCompleteRequestHandler(nullptr);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700522 }
523
Sunitha Harishc0ea7ae2020-10-30 02:37:30 -0500524 void readClientIp()
525 {
526 boost::system::error_code ec;
Sunitha Harishc0ea7ae2020-10-30 02:37:30 -0500527
Ed Tanous796ba932020-08-02 04:29:21 +0000528 boost::asio::ip::tcp::endpoint endpoint =
529 boost::beast::get_lowest_layer(adaptor).remote_endpoint(ec);
Ed Tanous4fa45df2023-09-01 14:20:50 -0700530
Ed Tanous796ba932020-08-02 04:29:21 +0000531 if (ec)
532 {
533 // If remote endpoint fails keep going. "ClientOriginIPAddress"
534 // will be empty.
535 BMCWEB_LOG_ERROR("Failed to get the client's IP Address. ec : {}",
536 ec);
537 return;
Sunitha Harishc0ea7ae2020-10-30 02:37:30 -0500538 }
Ed Tanous796ba932020-08-02 04:29:21 +0000539 ip = endpoint.address();
540 }
541
542 void disableAuth()
543 {
544 authenticationEnabled = false;
Sunitha Harishc0ea7ae2020-10-30 02:37:30 -0500545 }
546
Ed Tanous1abe55e2018-09-05 08:30:59 -0700547 private:
Ed Tanous1d1d7782024-04-09 12:54:08 -0700548 uint64_t getContentLengthLimit()
549 {
Ed Tanous83328312024-05-09 15:48:09 -0700550 if constexpr (!BMCWEB_INSECURE_DISABLE_AUTH)
Ed Tanous1d1d7782024-04-09 12:54:08 -0700551 {
Ed Tanous83328312024-05-09 15:48:09 -0700552 if (userSession == nullptr)
553 {
554 return loggedOutPostBodyLimit;
555 }
Ed Tanous1d1d7782024-04-09 12:54:08 -0700556 }
Ed Tanous1d1d7782024-04-09 12:54:08 -0700557
558 return httpReqBodyLimit;
559 }
560
561 // Returns true if content length was within limits
562 // Returns false if content length error has been returned
563 bool handleContentLengthError()
564 {
565 if (!parser)
566 {
Manojkiran Edaefff2b52024-06-18 18:01:46 +0530567 BMCWEB_LOG_CRITICAL("Parser was null");
Ed Tanous1d1d7782024-04-09 12:54:08 -0700568 return false;
569 }
570 const boost::optional<uint64_t> contentLength =
571 parser->content_length();
572 if (!contentLength)
573 {
574 BMCWEB_LOG_DEBUG("{} No content length available", logPtr(this));
575 return true;
576 }
577
578 uint64_t maxAllowedContentLength = getContentLengthLimit();
579
580 if (*contentLength > maxAllowedContentLength)
581 {
582 // If the users content limit is between the logged in
583 // and logged out limits They probably just didn't log
584 // in
585 if (*contentLength > loggedOutPostBodyLimit &&
586 *contentLength < httpReqBodyLimit)
587 {
588 BMCWEB_LOG_DEBUG(
589 "{} Content length {} valid, but greater than logged out"
590 " limit of {}. Setting unauthorized",
591 logPtr(this), *contentLength, loggedOutPostBodyLimit);
592 res.result(boost::beast::http::status::unauthorized);
593 }
594 else
595 {
596 // Otherwise they're over both limits, so inform
597 // them
598 BMCWEB_LOG_DEBUG(
599 "{} Content length {} was greater than global limit {}."
600 " Setting payload too large",
601 logPtr(this), *contentLength, httpReqBodyLimit);
602 res.result(boost::beast::http::status::payload_too_large);
603 }
604
605 keepAlive = false;
606 doWrite();
607 return false;
608 }
609
610 return true;
611 }
612
Ed Tanous116370d2024-10-08 10:37:28 -0700613 void afterReadHeaders(const std::shared_ptr<self_type>& /*self*/,
614 const boost::system::error_code& ec,
615 std::size_t bytesTransferred)
616 {
617 BMCWEB_LOG_DEBUG("{} async_read_header {} Bytes", logPtr(this),
618 bytesTransferred);
619
620 if (ec)
621 {
622 cancelDeadlineTimer();
623
624 if (ec == boost::beast::http::error::header_limit)
625 {
626 BMCWEB_LOG_ERROR("{} Header field too large, closing",
627 logPtr(this), ec.message());
628
629 res.result(boost::beast::http::status::
630 request_header_fields_too_large);
631 keepAlive = false;
632 doWrite();
633 return;
634 }
635 if (ec == boost::beast::http::error::end_of_stream)
636 {
637 BMCWEB_LOG_WARNING("{} End of stream, closing {}", logPtr(this),
638 ec);
639 hardClose();
640 return;
641 }
642
643 BMCWEB_LOG_DEBUG("{} Closing socket due to read error {}",
644 logPtr(this), ec.message());
645 gracefulClose();
646
647 return;
648 }
649
650 if (!parser)
651 {
652 BMCWEB_LOG_ERROR("Parser was unexpectedly null");
653 return;
654 }
655
Ed Tanous796ba932020-08-02 04:29:21 +0000656 if (authenticationEnabled)
Ed Tanous116370d2024-10-08 10:37:28 -0700657 {
658 boost::beast::http::verb method = parser->get().method();
Ed Tanous796ba932020-08-02 04:29:21 +0000659 userSession = authentication::authenticate(
Ed Tanous116370d2024-10-08 10:37:28 -0700660 ip, res, method, parser->get().base(), mtlsSession);
661 }
662
663 std::string_view expect =
664 parser->get()[boost::beast::http::field::expect];
665 if (bmcweb::asciiIEquals(expect, "100-continue"))
666 {
667 res.result(boost::beast::http::status::continue_);
668 doWrite();
669 return;
670 }
671
672 if (!handleContentLengthError())
673 {
674 return;
675 }
676
677 parser->body_limit(getContentLengthLimit());
678
679 if (parser->is_done())
680 {
681 handle();
682 return;
683 }
684
685 doRead();
686 }
687
Ed Tanous1abe55e2018-09-05 08:30:59 -0700688 void doReadHeaders()
689 {
Ed Tanous62598e32023-07-17 17:06:25 -0700690 BMCWEB_LOG_DEBUG("{} doReadHeaders", logPtr(this));
Ed Tanouse01d0c32023-06-30 13:21:32 -0700691 if (!parser)
692 {
Ed Tanous1d1d7782024-04-09 12:54:08 -0700693 BMCWEB_LOG_CRITICAL("Parser was not initialized.");
Ed Tanouse01d0c32023-06-30 13:21:32 -0700694 return;
695 }
Ed Tanous796ba932020-08-02 04:29:21 +0000696
697 if (httpType == HttpType::HTTP)
698 {
699 boost::beast::http::async_read_header(
700 adaptor.next_layer(), buffer, *parser,
701 std::bind_front(&self_type::afterReadHeaders, this,
702 shared_from_this()));
703 }
704 else
705 {
706 boost::beast::http::async_read_header(
707 adaptor, buffer, *parser,
708 std::bind_front(&self_type::afterReadHeaders, this,
709 shared_from_this()));
710 }
Ed Tanous116370d2024-10-08 10:37:28 -0700711 }
Ed Tanous52e31622024-01-23 16:31:11 -0800712
Ed Tanous116370d2024-10-08 10:37:28 -0700713 void afterRead(const std::shared_ptr<self_type>& /*self*/,
714 const boost::system::error_code& ec,
715 std::size_t bytesTransferred)
716 {
717 BMCWEB_LOG_DEBUG("{} async_read_some {} Bytes", logPtr(this),
718 bytesTransferred);
719
720 if (ec)
721 {
722 BMCWEB_LOG_ERROR("{} Error while reading: {}", logPtr(this),
723 ec.message());
724 if (ec == boost::beast::http::error::body_limit)
725 {
726 if (handleContentLengthError())
Ed Tanous1d1d7782024-04-09 12:54:08 -0700727 {
Ed Tanous116370d2024-10-08 10:37:28 -0700728 BMCWEB_LOG_CRITICAL("Body length limit reached, "
729 "but no content-length "
730 "available? Should never happen");
731 res.result(
732 boost::beast::http::status::internal_server_error);
733 keepAlive = false;
Ed Tanous1d1d7782024-04-09 12:54:08 -0700734 doWrite();
Ed Tanous1d1d7782024-04-09 12:54:08 -0700735 }
Ed Tanous116370d2024-10-08 10:37:28 -0700736 return;
737 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400738
Ed Tanous116370d2024-10-08 10:37:28 -0700739 gracefulClose();
740 return;
741 }
Ed Tanous1d1d7782024-04-09 12:54:08 -0700742
Ed Tanous116370d2024-10-08 10:37:28 -0700743 // If the user is logged in, allow them to send files
744 // incrementally one piece at a time. If authentication is
745 // disabled then there is no user session hence always allow to
746 // send one piece at a time.
747 if (userSession != nullptr)
748 {
749 cancelDeadlineTimer();
750 }
Ed Tanous1d1d7782024-04-09 12:54:08 -0700751
Ed Tanous116370d2024-10-08 10:37:28 -0700752 if (!parser)
753 {
754 BMCWEB_LOG_ERROR("Parser was unexpectedly null");
755 return;
756 }
757 if (!parser->is_done())
758 {
759 doRead();
760 return;
761 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700762
Ed Tanous116370d2024-10-08 10:37:28 -0700763 cancelDeadlineTimer();
764 handle();
Ed Tanous1abe55e2018-09-05 08:30:59 -0700765 }
766
767 void doRead()
768 {
Ed Tanous62598e32023-07-17 17:06:25 -0700769 BMCWEB_LOG_DEBUG("{} doRead", logPtr(this));
Ed Tanouse01d0c32023-06-30 13:21:32 -0700770 if (!parser)
771 {
772 return;
773 }
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800774 startDeadline();
Ed Tanous796ba932020-08-02 04:29:21 +0000775 if (httpType == HttpType::HTTP)
776 {
777 boost::beast::http::async_read_some(
778 adaptor.next_layer(), buffer, *parser,
779 std::bind_front(&self_type::afterRead, this,
780 shared_from_this()));
781 }
782 else
783 {
784 boost::beast::http::async_read_some(
785 adaptor, buffer, *parser,
786 std::bind_front(&self_type::afterRead, this,
787 shared_from_this()));
788 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700789 }
790
Ed Tanous27b0cf92023-08-07 12:02:40 -0700791 void afterDoWrite(const std::shared_ptr<self_type>& /*self*/,
792 const boost::system::error_code& ec,
793 std::size_t bytesTransferred)
794 {
Ed Tanous0242baf2024-05-16 19:52:47 -0700795 BMCWEB_LOG_DEBUG("{} async_write wrote {} bytes, ec={}", logPtr(this),
Ed Tanous1d1d7782024-04-09 12:54:08 -0700796 bytesTransferred, ec);
Ed Tanous27b0cf92023-08-07 12:02:40 -0700797
798 cancelDeadlineTimer();
799
Ed Tanous0242baf2024-05-16 19:52:47 -0700800 if (ec == boost::system::errc::operation_would_block ||
801 ec == boost::system::errc::resource_unavailable_try_again)
802 {
803 doWrite();
804 return;
805 }
Ed Tanous27b0cf92023-08-07 12:02:40 -0700806 if (ec)
807 {
808 BMCWEB_LOG_DEBUG("{} from write(2)", logPtr(this));
809 return;
810 }
Ed Tanous1d1d7782024-04-09 12:54:08 -0700811
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800812 if (res.result() == boost::beast::http::status::switching_protocols)
813 {
Ed Tanous796ba932020-08-02 04:29:21 +0000814 upgradeToHttp2();
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800815 return;
816 }
817
Ed Tanous1d1d7782024-04-09 12:54:08 -0700818 if (res.result() == boost::beast::http::status::continue_)
819 {
820 // Reset the result to ok
821 res.result(boost::beast::http::status::ok);
822 doRead();
823 return;
824 }
825
Ed Tanous27b0cf92023-08-07 12:02:40 -0700826 if (!keepAlive)
827 {
Ed Tanous1d1d7782024-04-09 12:54:08 -0700828 BMCWEB_LOG_DEBUG("{} keepalive not set. Closing socket",
829 logPtr(this));
830
831 gracefulClose();
Ed Tanous27b0cf92023-08-07 12:02:40 -0700832 return;
833 }
834
835 BMCWEB_LOG_DEBUG("{} Clearing response", logPtr(this));
836 res.clear();
Ed Tanous1d1d7782024-04-09 12:54:08 -0700837 initParser();
Ed Tanous27b0cf92023-08-07 12:02:40 -0700838
839 userSession = nullptr;
840
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700841 req->clear();
Ed Tanous27b0cf92023-08-07 12:02:40 -0700842 doReadHeaders();
843 }
844
Ed Tanous52e31622024-01-23 16:31:11 -0800845 void doWrite()
Ed Tanous1abe55e2018-09-05 08:30:59 -0700846 {
Ed Tanous62598e32023-07-17 17:06:25 -0700847 BMCWEB_LOG_DEBUG("{} doWrite", logPtr(this));
Ed Tanous52e31622024-01-23 16:31:11 -0800848 res.preparePayload();
Ed Tanous27b0cf92023-08-07 12:02:40 -0700849
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800850 startDeadline();
Ed Tanous796ba932020-08-02 04:29:21 +0000851 if (httpType == HttpType::HTTP)
852 {
853 boost::beast::async_write(
854 adaptor.next_layer(),
855 boost::beast::http::message_generator(std::move(res.response)),
856 std::bind_front(&self_type::afterDoWrite, this,
857 shared_from_this()));
858 }
859 else
860 {
861 boost::beast::async_write(
862 adaptor,
863 boost::beast::http::message_generator(std::move(res.response)),
864 std::bind_front(&self_type::afterDoWrite, this,
865 shared_from_this()));
866 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700867 }
868
Ed Tanous1abe55e2018-09-05 08:30:59 -0700869 void cancelDeadlineTimer()
870 {
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800871 timer.cancel();
Ed Tanous1abe55e2018-09-05 08:30:59 -0700872 }
873
Ed Tanous116370d2024-10-08 10:37:28 -0700874 void afterTimerWait(const std::weak_ptr<self_type>& weakSelf,
875 const boost::system::error_code& ec)
876 {
877 // Note, we are ignoring other types of errors here; If the timer
878 // failed for any reason, we should still close the connection
879 std::shared_ptr<Connection<Adaptor, Handler>> self = weakSelf.lock();
880 if (!self)
881 {
882 if (ec == boost::asio::error::operation_aborted)
883 {
884 BMCWEB_LOG_DEBUG(
885 "{} Timer canceled on connection being destroyed",
886 logPtr(self.get()));
887 }
888 else
889 {
890 BMCWEB_LOG_CRITICAL("{} Failed to capture connection",
891 logPtr(self.get()));
892 }
893 return;
894 }
895
896 self->timerStarted = false;
897
898 if (ec)
899 {
900 if (ec == boost::asio::error::operation_aborted)
901 {
902 BMCWEB_LOG_DEBUG("{} Timer canceled", logPtr(self.get()));
903 return;
904 }
905 BMCWEB_LOG_CRITICAL("{} Timer failed {}", logPtr(self.get()), ec);
906 }
907
908 BMCWEB_LOG_WARNING("{} Connection timed out, hard closing",
909 logPtr(self.get()));
910
911 self->hardClose();
912 }
913
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800914 void startDeadline()
Ed Tanous1abe55e2018-09-05 08:30:59 -0700915 {
Ed Tanous7d243eb2023-01-23 15:57:41 -0800916 // Timer is already started so no further action is required.
917 if (timerStarted)
918 {
919 return;
920 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700921
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800922 std::chrono::seconds timeout(15);
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800923
924 std::weak_ptr<Connection<Adaptor, Handler>> weakSelf = weak_from_this();
925 timer.expires_after(timeout);
Ed Tanous116370d2024-10-08 10:37:28 -0700926 timer.async_wait(std::bind_front(&self_type::afterTimerWait, this,
927 weak_from_this()));
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800928
Ed Tanous7d243eb2023-01-23 15:57:41 -0800929 timerStarted = true;
Ed Tanous62598e32023-07-17 17:06:25 -0700930 BMCWEB_LOG_DEBUG("{} timer started", logPtr(this));
Ed Tanous1abe55e2018-09-05 08:30:59 -0700931 }
932
Ed Tanous796ba932020-08-02 04:29:21 +0000933 bool authenticationEnabled = !BMCWEB_INSECURE_DISABLE_AUTH;
934 HttpType httpType = HttpType::BOTH;
935
936 boost::asio::ssl::stream<Adaptor> adaptor;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700937 Handler* handler;
Ed Tanous1d1d7782024-04-09 12:54:08 -0700938
939 boost::asio::ip::address ip;
940
Ed Tanousa24526d2018-12-10 15:17:59 -0800941 // Making this a std::optional allows it to be efficiently destroyed and
Ed Tanous1abe55e2018-09-05 08:30:59 -0700942 // re-created on Connection reset
Ed Tanousb2896142024-01-31 15:25:47 -0800943 std::optional<boost::beast::http::request_parser<bmcweb::HttpBody>> parser;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700944
Ed Tanous3112a142018-11-29 15:45:10 -0800945 boost::beast::flat_static_buffer<8192> buffer;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700946
Jonathan Doman102a4cd2024-04-15 16:56:23 -0700947 std::shared_ptr<crow::Request> req;
Ed Tanous89cda632024-04-16 08:45:54 -0700948 std::string accept;
Ed Tanouscd7dbb32025-02-01 12:37:56 -0800949 std::string http2settings;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700950 crow::Response res;
Ed Tanous52cc1122020-07-18 13:51:21 -0700951
John Edward Broadbent59b98b22021-07-13 15:36:32 -0700952 std::shared_ptr<persistent_data::UserSession> userSession;
Boleslaw Ogonczyk Makowskib4963072023-02-06 09:59:58 +0100953 std::shared_ptr<persistent_data::UserSession> mtlsSession;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700954
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800955 boost::asio::steady_timer timer;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700956
Ed Tanous4cdc2e82023-01-13 10:03:22 -0800957 bool keepAlive = true;
958
Ed Tanous7d243eb2023-01-23 15:57:41 -0800959 bool timerStarted = false;
960
Ed Tanous1abe55e2018-09-05 08:30:59 -0700961 std::function<std::string()>& getCachedDateStr;
Jan Sowinskiee52ae12020-01-09 16:28:32 +0000962
963 using std::enable_shared_from_this<
Ed Tanous52cc1122020-07-18 13:51:21 -0700964 Connection<Adaptor, Handler>>::shared_from_this;
Ed Tanous5dfb5b22021-12-03 11:24:53 -0800965
966 using std::enable_shared_from_this<
967 Connection<Adaptor, Handler>>::weak_from_this;
Ed Tanous3112a142018-11-29 15:45:10 -0800968};
Ed Tanous1abe55e2018-09-05 08:30:59 -0700969} // namespace crow