Skip to main content

cf_mach/nq_core/body/
mod.rs

1// Copyright (c) 2023-2024 Cloudflare, Inc.
2// Licensed under the BSD-3-Clause license found in the LICENSE file or at https://opensource.org/licenses/BSD-3-Clause
3
4mod counting_body;
5mod upload_body;
6
7use std::convert::Infallible;
8use std::sync::Arc;
9use tokio::sync::RwLock;
10
11use http::{HeaderMap, HeaderValue};
12use http_body_util::{Empty, combinators::BoxBody};
13use hyper::body::Bytes;
14use tokio::sync::mpsc;
15
16/// A simple boxed body.
17pub type NqBody = BoxBody<Bytes, Infallible>;
18
19/// Creates an empty body.
20pub fn empty() -> Empty<Bytes> {
21    Empty::new()
22}
23
24use crate::nq_core::{EstablishedConnection, Timestamp, connection::ConnectionTiming};
25
26pub use self::{
27    counting_body::{BodyEvent, CountingBody},
28    upload_body::UploadBody,
29};
30
31/// A body that is currently being sent or received.
32pub struct InflightBody {
33    /// When the request that produced this body was started.
34    pub start: Timestamp,
35    /// The connection the body is being transferred on. Shared so further
36    /// requests can be sent on the same connection.
37    pub connection: Arc<RwLock<EstablishedConnection>>,
38    /// Connection setup timing, when this body created the connection.
39    pub timing: Option<ConnectionTiming>,
40    /// Byte-count and termination events for this body. The channel closing is
41    /// itself meaningful: it signals the body was dropped.
42    pub events: mpsc::UnboundedReceiver<BodyEvent>,
43    /// Headers associated with the transfer.
44    pub headers: HeaderMap<HeaderValue>,
45}