Skip to main content

libdd_capabilities/
http.rs

1// Copyright 2026-Present Datadog, Inc. https://www.datadoghq.com/
2// SPDX-License-Identifier: Apache-2.0
3
4//! HTTP capability trait and error types.
5//!
6//! Request and response types are provided by the [`http`] crate, which is a
7//! pure-types crate with no platform dependencies (compiles on wasm). The body
8//! type is [`bytes::Bytes`].
9
10use crate::maybe_send::MaybeSend;
11use core::future::Future;
12
13#[derive(Debug, thiserror::Error)]
14pub enum HttpError {
15    #[error("Network error: {0}")]
16    Network(anyhow::Error),
17    #[error("Request timed out")]
18    Timeout,
19    #[error("Response body error: {0}")]
20    ResponseBody(anyhow::Error),
21    #[error("Invalid request: {0}")]
22    InvalidRequest(anyhow::Error),
23    #[error("HTTP error: {0}")]
24    Other(anyhow::Error),
25}
26
27pub trait HttpClientCapability: Clone + std::fmt::Debug {
28    fn new_client() -> Self;
29
30    fn request(
31        &self,
32        req: http::Request<bytes::Bytes>,
33    ) -> impl Future<Output = Result<http::Response<bytes::Bytes>, HttpError>> + MaybeSend;
34}