Skip to content

Commit

Permalink
http: Add non-owning make_request to http client
Browse files Browse the repository at this point in the history
To satisfy scylla's s3 client with future retry implementation add non-owning `make_request` to http client which is similar to the existing `make_request` but it doesn't take ownership of `request` and `reply_handler`
  • Loading branch information
kreuzerkrieg committed Oct 6, 2024
1 parent 3c9c269 commit 048cb36
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
17 changes: 14 additions & 3 deletions include/seastar/http/client.hh
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private:
requires std::invocable<Fn, connection&>
auto with_new_connection(Fn&& fn, abort_source*);

future<> do_make_request(request req, reply_handler handle, abort_source*, std::optional<reply::status_type> expected);
future<> do_make_request(request& req, reply_handler& handle, abort_source*, std::optional<reply::status_type> expected);
future<> do_make_request(connection& con, request& req, reply_handler& handle, abort_source*, std::optional<reply::status_type> expected);

public:
Expand Down Expand Up @@ -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<reply::status_type> expected = std::nullopt);
future<> make_request(request&& req, reply_handler&& handle, std::optional<reply::status_type>&& expected = std::nullopt);

/**
* \brief Send the request and handle the response (abortable)
Expand All @@ -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<reply::status_type> expected = std::nullopt);
future<> make_request(request&& req, reply_handler&& handle, abort_source& as, std::optional<reply::status_type>&& 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<reply::status_type> expected = std::nullopt);

future<> make_request(request& req, reply_handler& handle, abort_source& as, std::optional<reply::status_type> expected = std::nullopt);

/**
* \brief Updates the maximum number of connections a client may have
Expand Down
24 changes: 17 additions & 7 deletions src/http/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<reply::status_type> 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<reply::status_type>&& 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<reply::status_type>&& 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<reply::status_type> 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<reply::status_type> 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<reply::status_type> 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<reply::status_type> 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<reply::status_type> 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) {
Expand All @@ -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<reply::status_type> expected) {
Expand Down

0 comments on commit 048cb36

Please sign in to comment.