Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 3 | #pragma once |
| 4 | #include "bmcweb_config.h" |
| 5 | |
| 6 | #include "async_resp.hpp" |
| 7 | #include "authentication.hpp" |
| 8 | #include "complete_response_fields.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 9 | #include "forward_unauthorized.hpp" |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 10 | #include "http_body.hpp" |
Ed Tanous | ebe4c57 | 2025-02-08 14:29:53 -0800 | [diff] [blame] | 11 | #include "http_connect_types.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 12 | #include "http_request.hpp" |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 13 | #include "http_response.hpp" |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 14 | #include "logging.hpp" |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 15 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 16 | // NOLINTNEXTLINE(misc-include-cleaner) |
| 17 | #include "nghttp2_adapters.hpp" |
| 18 | |
| 19 | #include <nghttp2/nghttp2.h> |
| 20 | #include <unistd.h> |
| 21 | |
| 22 | #include <boost/asio/buffer.hpp> |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 23 | #include <boost/asio/ssl/stream.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 24 | #include <boost/beast/core/error.hpp> |
| 25 | #include <boost/beast/http/field.hpp> |
| 26 | #include <boost/beast/http/fields.hpp> |
| 27 | #include <boost/beast/http/message.hpp> |
| 28 | #include <boost/beast/http/verb.hpp> |
| 29 | #include <boost/optional/optional.hpp> |
Ed Tanous | d088218 | 2024-01-26 23:45:25 -0800 | [diff] [blame] | 30 | #include <boost/system/error_code.hpp> |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 31 | |
Ed Tanous | d088218 | 2024-01-26 23:45:25 -0800 | [diff] [blame] | 32 | #include <array> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 33 | #include <bit> |
| 34 | #include <cstddef> |
| 35 | #include <cstdint> |
Ed Tanous | d088218 | 2024-01-26 23:45:25 -0800 | [diff] [blame] | 36 | #include <functional> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 37 | #include <map> |
Ed Tanous | d088218 | 2024-01-26 23:45:25 -0800 | [diff] [blame] | 38 | #include <memory> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 39 | #include <optional> |
| 40 | #include <span> |
Ed Tanous | 89cda63 | 2024-04-16 08:45:54 -0700 | [diff] [blame] | 41 | #include <string> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 42 | #include <string_view> |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 43 | #include <type_traits> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 44 | #include <utility> |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 45 | #include <vector> |
| 46 | |
| 47 | namespace crow |
| 48 | { |
| 49 | |
| 50 | struct Http2StreamData |
| 51 | { |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 52 | std::shared_ptr<Request> req = std::make_shared<Request>(); |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 53 | std::optional<bmcweb::HttpBody::reader> reqReader; |
Ed Tanous | 89cda63 | 2024-04-16 08:45:54 -0700 | [diff] [blame] | 54 | std::string accept; |
Ed Tanous | 47f2934 | 2024-03-19 12:18:06 -0700 | [diff] [blame] | 55 | Response res; |
Ed Tanous | b289614 | 2024-01-31 15:25:47 -0800 | [diff] [blame] | 56 | std::optional<bmcweb::HttpBody::writer> writer; |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | template <typename Adaptor, typename Handler> |
| 60 | class HTTP2Connection : |
| 61 | public std::enable_shared_from_this<HTTP2Connection<Adaptor, Handler>> |
| 62 | { |
| 63 | using self_type = HTTP2Connection<Adaptor, Handler>; |
| 64 | |
| 65 | public: |
Ed Tanous | ebe4c57 | 2025-02-08 14:29:53 -0800 | [diff] [blame] | 66 | HTTP2Connection(boost::asio::ssl::stream<Adaptor>&& adaptorIn, |
| 67 | Handler* handlerIn, |
| 68 | std::function<std::string()>& getCachedDateStrF, |
| 69 | HttpType httpTypeIn) : |
| 70 | httpType(httpTypeIn), adaptor(std::move(adaptorIn)), |
| 71 | ngSession(initializeNghttp2Session()), handler(handlerIn), |
| 72 | getCachedDateStr(getCachedDateStrF) |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 73 | {} |
| 74 | |
| 75 | void start() |
| 76 | { |
| 77 | // Create the control stream |
Ed Tanous | f42e859 | 2023-08-25 10:47:44 -0700 | [diff] [blame] | 78 | streams[0]; |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 79 | |
| 80 | if (sendServerConnectionHeader() != 0) |
| 81 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 82 | BMCWEB_LOG_ERROR("send_server_connection_header failed"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 83 | return; |
| 84 | } |
| 85 | doRead(); |
| 86 | } |
| 87 | |
Ed Tanous | cd7dbb3 | 2025-02-01 12:37:56 -0800 | [diff] [blame] | 88 | void startFromSettings(std::string_view http2UpgradeSettings) |
| 89 | { |
| 90 | int ret = ngSession.sessionUpgrade2(http2UpgradeSettings, |
| 91 | false /*head_request*/); |
| 92 | if (ret != 0) |
| 93 | { |
| 94 | BMCWEB_LOG_ERROR("Failed to load upgrade header"); |
| 95 | return; |
| 96 | } |
| 97 | // Create the control stream |
| 98 | streams[0]; |
| 99 | |
| 100 | if (sendServerConnectionHeader() != 0) |
| 101 | { |
| 102 | BMCWEB_LOG_ERROR("send_server_connection_header failed"); |
| 103 | return; |
| 104 | } |
| 105 | doRead(); |
| 106 | } |
| 107 | |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 108 | int sendServerConnectionHeader() |
| 109 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 110 | BMCWEB_LOG_DEBUG("send_server_connection_header()"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 111 | |
| 112 | uint32_t maxStreams = 4; |
| 113 | std::array<nghttp2_settings_entry, 2> iv = { |
| 114 | {{NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, maxStreams}, |
| 115 | {NGHTTP2_SETTINGS_ENABLE_PUSH, 0}}}; |
| 116 | int rv = ngSession.submitSettings(iv); |
| 117 | if (rv != 0) |
| 118 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 119 | BMCWEB_LOG_ERROR("Fatal error: {}", nghttp2_strerror(rv)); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 120 | return -1; |
| 121 | } |
Ed Tanous | d088218 | 2024-01-26 23:45:25 -0800 | [diff] [blame] | 122 | writeBuffer(); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 126 | static ssize_t fileReadCallback( |
| 127 | nghttp2_session* /* session */, int32_t streamId, uint8_t* buf, |
| 128 | size_t length, uint32_t* dataFlags, nghttp2_data_source* /*source*/, |
| 129 | void* userPtr) |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 130 | { |
Ed Tanous | f42e859 | 2023-08-25 10:47:44 -0700 | [diff] [blame] | 131 | self_type& self = userPtrToSelf(userPtr); |
| 132 | |
| 133 | auto streamIt = self.streams.find(streamId); |
| 134 | if (streamIt == self.streams.end()) |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 135 | { |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 136 | return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; |
| 137 | } |
Ed Tanous | f42e859 | 2023-08-25 10:47:44 -0700 | [diff] [blame] | 138 | Http2StreamData& stream = streamIt->second; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 139 | BMCWEB_LOG_DEBUG("File read callback length: {}", length); |
Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame] | 140 | if (!stream.writer) |
| 141 | { |
| 142 | return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; |
| 143 | } |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 144 | boost::beast::error_code ec; |
| 145 | boost::optional<std::pair<boost::asio::const_buffer, bool>> out = |
| 146 | stream.writer->getWithMaxSize(ec, length); |
| 147 | if (ec) |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 148 | { |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 149 | BMCWEB_LOG_CRITICAL("Failed to get buffer"); |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 150 | return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; |
| 151 | } |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 152 | if (!out) |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 153 | { |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 154 | BMCWEB_LOG_ERROR("Empty file, setting EOF"); |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 155 | *dataFlags |= NGHTTP2_DATA_FLAG_EOF; |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | BMCWEB_LOG_DEBUG("Send chunk of size: {}", out->first.size()); |
| 160 | if (length < out->first.size()) |
| 161 | { |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 162 | BMCWEB_LOG_CRITICAL( |
| 163 | "Buffer overflow that should never happen happened"); |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 164 | // Should never happen because of length limit on get() above |
| 165 | return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; |
| 166 | } |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 167 | boost::asio::mutable_buffer writeableBuf(buf, length); |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 168 | BMCWEB_LOG_DEBUG("Copying {} bytes to buf", out->first.size()); |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 169 | size_t copied = boost::asio::buffer_copy(writeableBuf, out->first); |
| 170 | if (copied != out->first.size()) |
| 171 | { |
| 172 | BMCWEB_LOG_ERROR( |
| 173 | "Couldn't copy all {} bytes into buffer, only copied {}", |
| 174 | out->first.size(), copied); |
| 175 | return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; |
| 176 | } |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 177 | |
| 178 | if (!out->second) |
| 179 | { |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 180 | BMCWEB_LOG_DEBUG("Setting EOF flag"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 181 | *dataFlags |= NGHTTP2_DATA_FLAG_EOF; |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 182 | } |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 183 | return static_cast<ssize_t>(copied); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | nghttp2_nv headerFromStringViews(std::string_view name, |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 187 | std::string_view value, uint8_t flags) |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 188 | { |
| 189 | uint8_t* nameData = std::bit_cast<uint8_t*>(name.data()); |
| 190 | uint8_t* valueData = std::bit_cast<uint8_t*>(value.data()); |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 191 | return {nameData, valueData, name.size(), value.size(), flags}; |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | int sendResponse(Response& completedRes, int32_t streamId) |
| 195 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 196 | BMCWEB_LOG_DEBUG("send_response stream_id:{}", streamId); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 197 | |
| 198 | auto it = streams.find(streamId); |
| 199 | if (it == streams.end()) |
| 200 | { |
| 201 | close(); |
| 202 | return -1; |
| 203 | } |
Ed Tanous | 499b5b4 | 2024-04-06 08:39:18 -0700 | [diff] [blame] | 204 | Http2StreamData& stream = it->second; |
| 205 | Response& res = stream.res; |
| 206 | res = std::move(completedRes); |
Ed Tanous | 499b5b4 | 2024-04-06 08:39:18 -0700 | [diff] [blame] | 207 | |
Ed Tanous | 89cda63 | 2024-04-16 08:45:54 -0700 | [diff] [blame] | 208 | completeResponseFields(stream.accept, res); |
Ed Tanous | 499b5b4 | 2024-04-06 08:39:18 -0700 | [diff] [blame] | 209 | res.addHeader(boost::beast::http::field::date, getCachedDateStr()); |
| 210 | res.preparePayload(); |
| 211 | |
| 212 | boost::beast::http::fields& fields = res.fields(); |
| 213 | std::string code = std::to_string(res.resultInt()); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 214 | std::vector<nghttp2_nv> hdr; |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 215 | hdr.emplace_back( |
| 216 | headerFromStringViews(":status", code, NGHTTP2_NV_FLAG_NONE)); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 217 | for (const boost::beast::http::fields::value_type& header : fields) |
| 218 | { |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 219 | hdr.emplace_back(headerFromStringViews( |
Ed Tanous | d088218 | 2024-01-26 23:45:25 -0800 | [diff] [blame] | 220 | header.name_string(), header.value(), NGHTTP2_NV_FLAG_NONE)); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 221 | } |
Ed Tanous | b289614 | 2024-01-31 15:25:47 -0800 | [diff] [blame] | 222 | http::response<bmcweb::HttpBody>& fbody = res.response; |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 223 | stream.writer.emplace(fbody.base(), fbody.body()); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 224 | |
| 225 | nghttp2_data_provider dataPrd{ |
Ed Tanous | f42e859 | 2023-08-25 10:47:44 -0700 | [diff] [blame] | 226 | .source = {.fd = 0}, |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 227 | .read_callback = fileReadCallback, |
| 228 | }; |
| 229 | |
| 230 | int rv = ngSession.submitResponse(streamId, hdr, &dataPrd); |
| 231 | if (rv != 0) |
| 232 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 233 | BMCWEB_LOG_ERROR("Fatal error: {}", nghttp2_strerror(rv)); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 234 | close(); |
| 235 | return -1; |
| 236 | } |
Ed Tanous | d088218 | 2024-01-26 23:45:25 -0800 | [diff] [blame] | 237 | writeBuffer(); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | nghttp2_session initializeNghttp2Session() |
| 243 | { |
| 244 | nghttp2_session_callbacks callbacks; |
| 245 | callbacks.setOnFrameRecvCallback(onFrameRecvCallbackStatic); |
| 246 | callbacks.setOnStreamCloseCallback(onStreamCloseCallbackStatic); |
| 247 | callbacks.setOnHeaderCallback(onHeaderCallbackStatic); |
| 248 | callbacks.setOnBeginHeadersCallback(onBeginHeadersCallbackStatic); |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 249 | callbacks.setOnDataChunkRecvCallback(onDataChunkRecvStatic); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 250 | |
| 251 | nghttp2_session session(callbacks); |
| 252 | session.setUserData(this); |
| 253 | |
| 254 | return session; |
| 255 | } |
| 256 | |
| 257 | int onRequestRecv(int32_t streamId) |
| 258 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 259 | BMCWEB_LOG_DEBUG("on_request_recv"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 260 | |
| 261 | auto it = streams.find(streamId); |
| 262 | if (it == streams.end()) |
| 263 | { |
| 264 | close(); |
| 265 | return -1; |
| 266 | } |
Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame] | 267 | auto& reqReader = it->second.reqReader; |
| 268 | if (reqReader) |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 269 | { |
| 270 | boost::beast::error_code ec; |
Ed Tanous | daadfb2 | 2024-12-20 09:25:54 -0800 | [diff] [blame] | 271 | bmcweb::HttpBody::reader::finish(ec); |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 272 | if (ec) |
| 273 | { |
| 274 | BMCWEB_LOG_CRITICAL("Failed to finalize payload"); |
| 275 | close(); |
| 276 | return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; |
| 277 | } |
| 278 | } |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 279 | crow::Request& thisReq = *it->second.req; |
Ed Tanous | 89cda63 | 2024-04-16 08:45:54 -0700 | [diff] [blame] | 280 | it->second.accept = thisReq.getHeaderValue("Accept"); |
| 281 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 282 | BMCWEB_LOG_DEBUG("Handling {} \"{}\"", logPtr(&thisReq), |
| 283 | thisReq.url().encoded_path()); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 284 | |
Ed Tanous | f42e859 | 2023-08-25 10:47:44 -0700 | [diff] [blame] | 285 | crow::Response& thisRes = it->second.res; |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 286 | |
| 287 | thisRes.setCompleteRequestHandler( |
| 288 | [this, streamId](Response& completeRes) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 289 | BMCWEB_LOG_DEBUG("res.completeRequestHandler called"); |
| 290 | if (sendResponse(completeRes, streamId) != 0) |
| 291 | { |
| 292 | close(); |
| 293 | return; |
| 294 | } |
| 295 | }); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 296 | auto asyncResp = |
Ed Tanous | f42e859 | 2023-08-25 10:47:44 -0700 | [diff] [blame] | 297 | std::make_shared<bmcweb::AsyncResp>(std::move(it->second.res)); |
Ed Tanous | 8332831 | 2024-05-09 15:48:09 -0700 | [diff] [blame] | 298 | if constexpr (!BMCWEB_INSECURE_DISABLE_AUTH) |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 299 | { |
Ed Tanous | 8332831 | 2024-05-09 15:48:09 -0700 | [diff] [blame] | 300 | thisReq.session = crow::authentication::authenticate( |
| 301 | {}, asyncResp->res, thisReq.method(), thisReq.req, nullptr); |
| 302 | if (!crow::authentication::isOnAllowlist(thisReq.url().path(), |
| 303 | thisReq.method()) && |
| 304 | thisReq.session == nullptr) |
Ed Tanous | 499b5b4 | 2024-04-06 08:39:18 -0700 | [diff] [blame] | 305 | { |
Ed Tanous | 8332831 | 2024-05-09 15:48:09 -0700 | [diff] [blame] | 306 | BMCWEB_LOG_WARNING("Authentication failed"); |
| 307 | forward_unauthorized::sendUnauthorized( |
| 308 | thisReq.url().encoded_path(), |
| 309 | thisReq.getHeaderValue("X-Requested-With"), |
| 310 | thisReq.getHeaderValue("Accept"), asyncResp->res); |
| 311 | return 0; |
Ed Tanous | 499b5b4 | 2024-04-06 08:39:18 -0700 | [diff] [blame] | 312 | } |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 313 | } |
Ed Tanous | 8332831 | 2024-05-09 15:48:09 -0700 | [diff] [blame] | 314 | std::string_view expected = |
| 315 | thisReq.getHeaderValue(boost::beast::http::field::if_none_match); |
| 316 | BMCWEB_LOG_DEBUG("Setting expected hash {}", expected); |
| 317 | if (!expected.empty()) |
| 318 | { |
| 319 | asyncResp->res.setExpectedHash(expected); |
| 320 | } |
| 321 | handler->handle(it->second.req, asyncResp); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 322 | return 0; |
| 323 | } |
| 324 | |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 325 | int onDataChunkRecvCallback(uint8_t /*flags*/, int32_t streamId, |
| 326 | const uint8_t* data, size_t len) |
| 327 | { |
| 328 | auto thisStream = streams.find(streamId); |
| 329 | if (thisStream == streams.end()) |
| 330 | { |
| 331 | BMCWEB_LOG_ERROR("Unknown stream{}", streamId); |
| 332 | close(); |
| 333 | return -1; |
| 334 | } |
Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame] | 335 | |
| 336 | std::optional<bmcweb::HttpBody::reader>& reqReader = |
| 337 | thisStream->second.reqReader; |
| 338 | if (!reqReader) |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 339 | { |
Ed Tanous | 8e5cc7b | 2024-04-02 11:00:54 -0700 | [diff] [blame] | 340 | reqReader.emplace( |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 341 | bmcweb::HttpBody::reader(thisStream->second.req->req.base(), |
| 342 | thisStream->second.req->req.body())); |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 343 | } |
| 344 | boost::beast::error_code ec; |
Ed Tanous | d547d8d | 2024-03-16 18:04:41 -0700 | [diff] [blame] | 345 | reqReader->put(boost::asio::const_buffer(data, len), ec); |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 346 | if (ec) |
| 347 | { |
| 348 | BMCWEB_LOG_CRITICAL("Failed to write payload"); |
| 349 | return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; |
| 350 | } |
| 351 | return 0; |
| 352 | } |
| 353 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 354 | static int onDataChunkRecvStatic( |
| 355 | nghttp2_session* /* session */, uint8_t flags, int32_t streamId, |
| 356 | const uint8_t* data, size_t len, void* userData) |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 357 | { |
| 358 | BMCWEB_LOG_DEBUG("on_frame_recv_callback"); |
| 359 | if (userData == nullptr) |
| 360 | { |
| 361 | BMCWEB_LOG_CRITICAL("user data was null?"); |
| 362 | return NGHTTP2_ERR_CALLBACK_FAILURE; |
| 363 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 364 | return userPtrToSelf(userData).onDataChunkRecvCallback( |
| 365 | flags, streamId, data, len); |
Ed Tanous | 325310d | 2024-03-15 09:05:04 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 368 | int onFrameRecvCallback(const nghttp2_frame& frame) |
| 369 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 370 | BMCWEB_LOG_DEBUG("frame type {}", static_cast<int>(frame.hd.type)); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 371 | switch (frame.hd.type) |
| 372 | { |
| 373 | case NGHTTP2_DATA: |
| 374 | case NGHTTP2_HEADERS: |
| 375 | // Check that the client request has finished |
| 376 | if ((frame.hd.flags & NGHTTP2_FLAG_END_STREAM) != 0) |
| 377 | { |
| 378 | return onRequestRecv(frame.hd.stream_id); |
| 379 | } |
| 380 | break; |
| 381 | default: |
| 382 | break; |
| 383 | } |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static int onFrameRecvCallbackStatic(nghttp2_session* /* session */, |
| 388 | const nghttp2_frame* frame, |
| 389 | void* userData) |
| 390 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 391 | BMCWEB_LOG_DEBUG("on_frame_recv_callback"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 392 | if (userData == nullptr) |
| 393 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 394 | BMCWEB_LOG_CRITICAL("user data was null?"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 395 | return NGHTTP2_ERR_CALLBACK_FAILURE; |
| 396 | } |
| 397 | if (frame == nullptr) |
| 398 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 399 | BMCWEB_LOG_CRITICAL("frame was null?"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 400 | return NGHTTP2_ERR_CALLBACK_FAILURE; |
| 401 | } |
| 402 | return userPtrToSelf(userData).onFrameRecvCallback(*frame); |
| 403 | } |
| 404 | |
| 405 | static self_type& userPtrToSelf(void* userData) |
| 406 | { |
| 407 | // This method exists to keep the unsafe reinterpret cast in one |
| 408 | // place. |
| 409 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) |
| 410 | return *reinterpret_cast<self_type*>(userData); |
| 411 | } |
| 412 | |
| 413 | static int onStreamCloseCallbackStatic(nghttp2_session* /* session */, |
| 414 | int32_t streamId, |
| 415 | uint32_t /*unused*/, void* userData) |
| 416 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 417 | BMCWEB_LOG_DEBUG("on_stream_close_callback stream {}", streamId); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 418 | if (userData == nullptr) |
| 419 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 420 | BMCWEB_LOG_CRITICAL("user data was null?"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 421 | return NGHTTP2_ERR_CALLBACK_FAILURE; |
| 422 | } |
Ed Tanous | f42e859 | 2023-08-25 10:47:44 -0700 | [diff] [blame] | 423 | if (userPtrToSelf(userData).streams.erase(streamId) <= 0) |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 424 | { |
| 425 | return -1; |
| 426 | } |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | int onHeaderCallback(const nghttp2_frame& frame, |
| 431 | std::span<const uint8_t> name, |
| 432 | std::span<const uint8_t> value) |
| 433 | { |
| 434 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) |
| 435 | std::string_view nameSv(reinterpret_cast<const char*>(name.data()), |
| 436 | name.size()); |
| 437 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) |
| 438 | std::string_view valueSv(reinterpret_cast<const char*>(value.data()), |
| 439 | value.size()); |
| 440 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 441 | BMCWEB_LOG_DEBUG("on_header_callback name: {} value {}", nameSv, |
| 442 | valueSv); |
Ed Tanous | a07e981 | 2024-03-19 10:31:13 -0700 | [diff] [blame] | 443 | if (frame.hd.type != NGHTTP2_HEADERS) |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 444 | { |
Ed Tanous | a07e981 | 2024-03-19 10:31:13 -0700 | [diff] [blame] | 445 | return 0; |
| 446 | } |
| 447 | if (frame.headers.cat != NGHTTP2_HCAT_REQUEST) |
| 448 | { |
| 449 | return 0; |
| 450 | } |
| 451 | auto thisStream = streams.find(frame.hd.stream_id); |
| 452 | if (thisStream == streams.end()) |
| 453 | { |
| 454 | BMCWEB_LOG_ERROR("Unknown stream{}", frame.hd.stream_id); |
| 455 | close(); |
| 456 | return -1; |
| 457 | } |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 458 | |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 459 | crow::Request& thisReq = *thisStream->second.req; |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 460 | |
Ed Tanous | a07e981 | 2024-03-19 10:31:13 -0700 | [diff] [blame] | 461 | if (nameSv == ":path") |
| 462 | { |
| 463 | thisReq.target(valueSv); |
| 464 | } |
| 465 | else if (nameSv == ":method") |
| 466 | { |
| 467 | boost::beast::http::verb verb = |
| 468 | boost::beast::http::string_to_verb(valueSv); |
| 469 | if (verb == boost::beast::http::verb::unknown) |
| 470 | { |
| 471 | BMCWEB_LOG_ERROR("Unknown http verb {}", valueSv); |
Ed Tanous | 50bfc91 | 2024-07-29 14:20:50 -0700 | [diff] [blame] | 472 | verb = boost::beast::http::verb::trace; |
Ed Tanous | a07e981 | 2024-03-19 10:31:13 -0700 | [diff] [blame] | 473 | } |
Myung Bae | 1873a04 | 2024-04-01 09:27:39 -0500 | [diff] [blame] | 474 | thisReq.method(verb); |
Ed Tanous | a07e981 | 2024-03-19 10:31:13 -0700 | [diff] [blame] | 475 | } |
| 476 | else if (nameSv == ":scheme") |
| 477 | { |
| 478 | // Nothing to check on scheme |
| 479 | } |
| 480 | else |
| 481 | { |
Myung Bae | 1873a04 | 2024-04-01 09:27:39 -0500 | [diff] [blame] | 482 | thisReq.addHeader(nameSv, valueSv); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 483 | } |
| 484 | return 0; |
| 485 | } |
| 486 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 487 | static int onHeaderCallbackStatic( |
| 488 | nghttp2_session* /* session */, const nghttp2_frame* frame, |
| 489 | const uint8_t* name, size_t namelen, const uint8_t* value, |
| 490 | size_t vallen, uint8_t /* flags */, void* userData) |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 491 | { |
| 492 | if (userData == nullptr) |
| 493 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 494 | BMCWEB_LOG_CRITICAL("user data was null?"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 495 | return NGHTTP2_ERR_CALLBACK_FAILURE; |
| 496 | } |
| 497 | if (frame == nullptr) |
| 498 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 499 | BMCWEB_LOG_CRITICAL("frame was null?"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 500 | return NGHTTP2_ERR_CALLBACK_FAILURE; |
| 501 | } |
| 502 | if (name == nullptr) |
| 503 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 504 | BMCWEB_LOG_CRITICAL("name was null?"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 505 | return NGHTTP2_ERR_CALLBACK_FAILURE; |
| 506 | } |
| 507 | if (value == nullptr) |
| 508 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 509 | BMCWEB_LOG_CRITICAL("value was null?"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 510 | return NGHTTP2_ERR_CALLBACK_FAILURE; |
| 511 | } |
| 512 | return userPtrToSelf(userData).onHeaderCallback(*frame, {name, namelen}, |
| 513 | {value, vallen}); |
| 514 | } |
| 515 | |
| 516 | int onBeginHeadersCallback(const nghttp2_frame& frame) |
| 517 | { |
| 518 | if (frame.hd.type == NGHTTP2_HEADERS && |
| 519 | frame.headers.cat == NGHTTP2_HCAT_REQUEST) |
| 520 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 521 | BMCWEB_LOG_DEBUG("create stream for id {}", frame.hd.stream_id); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 522 | |
Ed Tanous | 3a49941 | 2024-06-05 16:05:35 -0700 | [diff] [blame] | 523 | streams.emplace(frame.hd.stream_id, Http2StreamData()); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 524 | } |
| 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | static int onBeginHeadersCallbackStatic(nghttp2_session* /* session */, |
| 529 | const nghttp2_frame* frame, |
| 530 | void* userData) |
| 531 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 532 | BMCWEB_LOG_DEBUG("on_begin_headers_callback"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 533 | if (userData == nullptr) |
| 534 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 535 | BMCWEB_LOG_CRITICAL("user data was null?"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 536 | return NGHTTP2_ERR_CALLBACK_FAILURE; |
| 537 | } |
| 538 | if (frame == nullptr) |
| 539 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 540 | BMCWEB_LOG_CRITICAL("frame was null?"); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 541 | return NGHTTP2_ERR_CALLBACK_FAILURE; |
| 542 | } |
| 543 | return userPtrToSelf(userData).onBeginHeadersCallback(*frame); |
| 544 | } |
| 545 | |
| 546 | static void afterWriteBuffer(const std::shared_ptr<self_type>& self, |
| 547 | const boost::system::error_code& ec, |
| 548 | size_t sendLength) |
| 549 | { |
| 550 | self->isWriting = false; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 551 | BMCWEB_LOG_DEBUG("Sent {}", sendLength); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 552 | if (ec) |
| 553 | { |
| 554 | self->close(); |
| 555 | return; |
| 556 | } |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 557 | self->writeBuffer(); |
| 558 | } |
| 559 | |
| 560 | void writeBuffer() |
| 561 | { |
| 562 | if (isWriting) |
| 563 | { |
| 564 | return; |
| 565 | } |
Ed Tanous | d088218 | 2024-01-26 23:45:25 -0800 | [diff] [blame] | 566 | std::span<const uint8_t> data = ngSession.memSend(); |
| 567 | if (data.empty()) |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 568 | { |
| 569 | return; |
| 570 | } |
| 571 | isWriting = true; |
Ed Tanous | ebe4c57 | 2025-02-08 14:29:53 -0800 | [diff] [blame] | 572 | if (httpType == HttpType::HTTPS) |
| 573 | { |
| 574 | boost::asio::async_write( |
| 575 | adaptor, boost::asio::const_buffer(data.data(), data.size()), |
| 576 | std::bind_front(afterWriteBuffer, shared_from_this())); |
| 577 | } |
| 578 | else if (httpType == HttpType::HTTP) |
| 579 | { |
| 580 | boost::asio::async_write( |
| 581 | adaptor.next_layer(), |
| 582 | boost::asio::const_buffer(data.data(), data.size()), |
| 583 | std::bind_front(afterWriteBuffer, shared_from_this())); |
| 584 | } |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 585 | } |
| 586 | |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 587 | void close() |
| 588 | { |
Ed Tanous | ebe4c57 | 2025-02-08 14:29:53 -0800 | [diff] [blame] | 589 | adaptor.next_layer().close(); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Ed Tanous | d088218 | 2024-01-26 23:45:25 -0800 | [diff] [blame] | 592 | void afterDoRead(const std::shared_ptr<self_type>& /*self*/, |
| 593 | const boost::system::error_code& ec, |
| 594 | size_t bytesTransferred) |
| 595 | { |
| 596 | BMCWEB_LOG_DEBUG("{} async_read_some {} Bytes", logPtr(this), |
| 597 | bytesTransferred); |
| 598 | |
| 599 | if (ec) |
| 600 | { |
| 601 | BMCWEB_LOG_ERROR("{} Error while reading: {}", logPtr(this), |
| 602 | ec.message()); |
| 603 | close(); |
| 604 | BMCWEB_LOG_DEBUG("{} from read(1)", logPtr(this)); |
| 605 | return; |
| 606 | } |
| 607 | std::span<uint8_t> bufferSpan{inBuffer.data(), bytesTransferred}; |
| 608 | |
| 609 | ssize_t readLen = ngSession.memRecv(bufferSpan); |
| 610 | if (readLen < 0) |
| 611 | { |
| 612 | BMCWEB_LOG_ERROR("nghttp2_session_mem_recv returned {}", readLen); |
| 613 | close(); |
| 614 | return; |
| 615 | } |
| 616 | writeBuffer(); |
| 617 | |
| 618 | doRead(); |
| 619 | } |
| 620 | |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 621 | void doRead() |
| 622 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 623 | BMCWEB_LOG_DEBUG("{} doRead", logPtr(this)); |
Ed Tanous | ebe4c57 | 2025-02-08 14:29:53 -0800 | [diff] [blame] | 624 | if (httpType == HttpType::HTTPS) |
| 625 | { |
| 626 | adaptor.async_read_some(boost::asio::buffer(inBuffer), |
| 627 | std::bind_front(&self_type::afterDoRead, |
| 628 | this, shared_from_this())); |
| 629 | } |
| 630 | else if (httpType == HttpType::HTTP) |
| 631 | { |
| 632 | adaptor.next_layer().async_read_some( |
| 633 | boost::asio::buffer(inBuffer), |
| 634 | std::bind_front(&self_type::afterDoRead, this, |
| 635 | shared_from_this())); |
| 636 | } |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | // A mapping from http2 stream ID to Stream Data |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 640 | std::map<int32_t, Http2StreamData> streams; |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 641 | |
Ed Tanous | d088218 | 2024-01-26 23:45:25 -0800 | [diff] [blame] | 642 | std::array<uint8_t, 8192> inBuffer{}; |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 643 | |
Ed Tanous | ebe4c57 | 2025-02-08 14:29:53 -0800 | [diff] [blame] | 644 | HttpType httpType = HttpType::BOTH; |
| 645 | boost::asio::ssl::stream<Adaptor> adaptor; |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 646 | bool isWriting = false; |
| 647 | |
| 648 | nghttp2_session ngSession; |
| 649 | |
| 650 | Handler* handler; |
| 651 | std::function<std::string()>& getCachedDateStr; |
| 652 | |
| 653 | using std::enable_shared_from_this< |
| 654 | HTTP2Connection<Adaptor, Handler>>::shared_from_this; |
| 655 | |
| 656 | using std::enable_shared_from_this< |
| 657 | HTTP2Connection<Adaptor, Handler>>::weak_from_this; |
| 658 | }; |
| 659 | } // namespace crow |