diff --git a/include/seastar/http/client.hh b/include/seastar/http/client.hh index 09e3b8d2ed..351fd219f7 100644 --- a/include/seastar/http/client.hh +++ b/include/seastar/http/client.hh @@ -199,7 +199,7 @@ private: requires std::invocable auto with_new_connection(Fn&& fn, abort_source*); - future<> do_make_request(request req, reply_handler handle, abort_source*, std::optional expected); + future<> do_make_request(request& req, reply_handler& handle, abort_source*, std::optional expected); future<> do_make_request(connection& con, request& req, reply_handler& handle, abort_source*, std::optional expected); public: @@ -283,7 +283,7 @@ public: * client may restart the whole request processing in case server closes the connection * in the middle of operation */ - future<> make_request(request req, reply_handler handle, std::optional expected = std::nullopt); + future<> make_request(request&& req, reply_handler&& handle, std::optional&& expected = std::nullopt); /** * \brief Send the request and handle the response (abortable) @@ -295,7 +295,18 @@ public: * \param as -- abort source that aborts the request * \param expected -- the optional expected reply status code, default is std::nullopt */ - future<> make_request(request req, reply_handler handle, abort_source& as, std::optional expected = std::nullopt); + future<> make_request(request&& req, reply_handler&& handle, abort_source& as, std::optional&& expected = std::nullopt); + + /** + * \brief Send the request and handle the response, same as \ref make_request() + * + * @attention Note that the method does not take the ownership of the + * `request and the `handle`, it caller's responsibility the make sure they + * are referencing valid instances + */ + future<> make_request(request& req, reply_handler& handle, std::optional expected = std::nullopt); + + future<> make_request(request& req, reply_handler& handle, abort_source& as, std::optional expected = std::nullopt); /** * \brief Updates the maximum number of connections a client may have diff --git a/src/http/client.cc b/src/http/client.cc index 4d618f7f8c..48b1a0187e 100644 --- a/src/http/client.cc +++ b/src/http/client.cc @@ -338,16 +338,27 @@ auto client::with_new_connection(Fn&& fn, abort_source* as) { }); } -future<> client::make_request(request req, reply_handler handle, std::optional expected) { - return do_make_request(std::move(req), std::move(handle), nullptr, std::move(expected)); +future<> client::make_request(request&& req, reply_handler&& handle, std::optional&& expected) { + return do_with(std::move(req), std::move(handle), [this, expected](request& req, reply_handler& handle) mutable { + return do_make_request(req, handle, nullptr, std::move(expected)); + }); +} + +future<> client::make_request(request&& req, reply_handler&& handle, abort_source& as, std::optional&& expected) { + return do_with(std::move(req), std::move(handle), [this, as{&as}, expected](request& req, reply_handler& handle) mutable { + return do_make_request(req, handle, as, std::move(expected)); + }); } -future<> client::make_request(request req, reply_handler handle, abort_source& as, std::optional expected) { - return do_make_request(std::move(req), std::move(handle), &as, std::move(expected)); +future<> client::make_request(request& req, reply_handler& handle, std::optional expected) { + return do_make_request(req, handle, nullptr, std::move(expected)); } -future<> client::do_make_request(request req, reply_handler handle, abort_source* as, std::optional expected) { - return do_with(std::move(req), std::move(handle), [this, as, expected] (request& req, reply_handler& handle) mutable { +future<> client::make_request(request& req, reply_handler& handle, abort_source& as, std::optional expected) { + return do_make_request(req, handle, &as, std::move(expected)); +} + +future<> client::do_make_request(request& req, reply_handler& handle, abort_source* as, std::optional expected) { return with_connection([this, &req, &handle, as, expected] (connection& con) { return do_make_request(con, req, handle, as, expected); }, as).handle_exception_type([this, &req, &handle, as, expected] (const std::system_error& ex) { @@ -371,7 +382,6 @@ future<> client::do_make_request(request req, reply_handler handle, abort_source return do_make_request(con, req, handle, as, expected); }, as); }); - }); } future<> client::do_make_request(connection& con, request& req, reply_handler& handle, abort_source* as, std::optional expected) {