|
| 1 | +// Copyright 2025 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef SRC_CLIENTS_ASYNC_CLIENT_ASYNC_HTTP_CLIENT_H_ |
| 16 | +#define SRC_CLIENTS_ASYNC_CLIENT_ASYNC_HTTP_CLIENT_H_ |
| 17 | + |
| 18 | +#include <memory> |
| 19 | +#include <string> |
| 20 | + |
| 21 | +#include "absl/container/flat_hash_map.h" |
| 22 | +#include "absl/functional/any_invocable.h" |
| 23 | +#include "absl/status/statusor.h" |
| 24 | +#include "absl/time/time.h" |
| 25 | + |
| 26 | +namespace privacy_sandbox::server_common::clients { |
| 27 | + |
| 28 | +// This provides access to the Metadata Object type |
| 29 | +using RequestMetadata = absl::flat_hash_map<std::string, std::string>; |
| 30 | + |
| 31 | +// Classes implementing this template and interface are able to execute |
| 32 | +// asynchronous requests. |
| 33 | +template <typename Request, typename Response, typename RawRequest = Request, |
| 34 | + typename RawResponse = Response> |
| 35 | +class AsyncHttpClient { |
| 36 | + public: |
| 37 | + virtual ~AsyncHttpClient() = default; |
| 38 | + |
| 39 | + // Executes the request asynchronously. |
| 40 | + // |
| 41 | + // request: the request object to execute. |
| 42 | + // metadata: Metadata to be passed to the client. |
| 43 | + // on_done: callback called when the request is finished executing. |
| 44 | + // timeout: a timeout value for the request. |
| 45 | + virtual absl::Status Execute( |
| 46 | + std::unique_ptr<Request> request, const RequestMetadata& metadata, |
| 47 | + absl::AnyInvocable<void(absl::StatusOr<std::unique_ptr<Response>>) &&> |
| 48 | + on_done, |
| 49 | + absl::Duration timeout, |
| 50 | + privacy_sandbox::server_common::log::PSLogContext& log_context = |
| 51 | + const_cast<privacy_sandbox::server_common::log::NoOpContext&>( |
| 52 | + privacy_sandbox::server_common::log::kNoOpContext)) const = 0; |
| 53 | +}; |
| 54 | + |
| 55 | +} // namespace privacy_sandbox::server_common::clients |
| 56 | + |
| 57 | +#endif // SRC_CLIENTS_ASYNC_CLIENT_ASYNC_HTTP_CLIENT_H_ |
0 commit comments