@@ -38,13 +38,12 @@ namespace http
3838 std::unique_ptr<ccf::tls::Context> ctx,
3939 const ccf::http::ParserConfiguration& configuration,
4040 const std::shared_ptr<ErrorReporter>& error_reporter_,
41- const std::shared_ptr<ccf::CommitCallbackSubsystem>& commit_callbacks =
42- nullptr ) :
41+ const std::shared_ptr<ccf::CommitCallbackSubsystem>& commit_callbacks_) :
4342 HTTPSession (session_id_, writer_factory, std::move(ctx)),
4443 request_parser (*this , configuration),
4544 rpc_map (std::move(rpc_map_)),
4645 error_reporter (error_reporter_),
47- commit_callbacks (commit_callbacks ),
46+ commit_callbacks (commit_callbacks_ ),
4847 interface_id (std::move(interface_id_))
4948 {}
5049
@@ -186,25 +185,29 @@ namespace http
186185 // maintain session consistency
187186 ccf::tasks::Resumable paused_task = ccf::tasks::pause_current_task ();
188187
188+ // shared_from_this returns a base session type
189+ std::shared_ptr<ccf::ThreadedSession> self = shared_from_this ();
190+
189191 // Register for a callback when this TxID is committed (or
190192 // invalidated)
191193 commit_callbacks->add_callback (
192194 tx_id,
193- [this , rpc_ctx, paused_task, committed_func](
195+ [self , rpc_ctx, paused_task, committed_func](
194196 ccf::TxID transaction_id, ccf::FinalTxStatus status) {
195197 // Let the handler modify the response
196198 committed_func (rpc_ctx, transaction_id, status);
197199
198200 // Write the response
199- this ->send_response (
201+ send_response_impl (
202+ *self,
200203 rpc_ctx->get_response_http_status (),
201204 rpc_ctx->get_response_headers (),
202205 rpc_ctx->get_response_trailers (),
203206 std::move (rpc_ctx->take_response_body ()));
204207
205208 if (rpc_ctx->terminate_session )
206209 {
207- close_session ();
210+ self-> close_session ();
208211 }
209212
210213 // Resume processing work for this session
@@ -240,11 +243,12 @@ namespace http
240243 }
241244 }
242245
243- bool send_response (
246+ static bool send_response_impl (
247+ ccf::ThreadedSession& session,
244248 ccf::http_status status_code,
245249 ccf::http::HeaderMap&& headers,
246250 ccf::http::HeaderMap&& trailers,
247- std::vector<uint8_t >&& body) override
251+ std::vector<uint8_t >&& body)
248252 {
249253 if (!trailers.empty ())
250254 {
@@ -263,9 +267,23 @@ namespace http
263267 false /* Don't overwrite any existing content-length header */
264268 );
265269
266- send_data (response.build_response ());
270+ session. send_data (response.build_response ());
267271 return true ;
268272 }
273+
274+ bool send_response (
275+ ccf::http_status status_code,
276+ ccf::http::HeaderMap&& headers,
277+ ccf::http::HeaderMap&& trailers,
278+ std::vector<uint8_t >&& body) override
279+ {
280+ return send_response_impl (
281+ *this ,
282+ status_code,
283+ std::move (headers),
284+ std::move (trailers),
285+ std::move (body));
286+ }
269287 };
270288
271289 class HTTPClientSession : public HTTPSession ,
0 commit comments