Skip to main content

pingora_core/protocols/http/
mod.rs

1// Copyright 2026 Cloudflare, Inc.
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//! HTTP/1.x and HTTP/2 implementation APIs
16
17pub mod authority;
18pub mod body_buffer;
19pub mod bridge;
20pub mod client;
21pub mod compression;
22pub mod conditional_filter;
23pub mod custom;
24pub mod date;
25pub mod error_resp;
26pub mod server;
27pub mod subrequest;
28pub mod v1;
29pub mod v2;
30
31pub use server::{ReusableHttpStream, Session as ServerSession};
32
33/// The Pingora server name string
34pub const SERVER_NAME: &[u8; 7] = b"Pingora";
35
36/// An enum to hold all possible HTTP response events.
37#[derive(Debug)]
38pub enum HttpTask {
39    /// the response header and the boolean end of response flag
40    Header(Box<pingora_http::ResponseHeader>, bool),
41    /// A piece of request or response body and the end of request/response boolean flag.
42    Body(Option<bytes::Bytes>, bool),
43    /// Request or response body bytes that have been upgraded on H1.1, and EOF bool flag.
44    UpgradedBody(Option<bytes::Bytes>, bool),
45    /// HTTP response trailer
46    Trailer(Option<Box<http::HeaderMap>>),
47    /// Signal that the response is already finished
48    Done,
49    /// Signal that the reading of the response encountered errors.
50    Failed(pingora_error::BError),
51}
52
53impl HttpTask {
54    /// Whether this [`HttpTask`] means the end of the response.
55    pub fn is_end(&self) -> bool {
56        match self {
57            HttpTask::Header(_, end) => *end,
58            HttpTask::Body(_, end) => *end,
59            HttpTask::UpgradedBody(_, end) => *end,
60            HttpTask::Trailer(_) => true,
61            HttpTask::Done => true,
62            HttpTask::Failed(_) => true,
63        }
64    }
65
66    /// The [`HttpTask`] type as string.
67    pub fn type_str(&self) -> &'static str {
68        match self {
69            HttpTask::Header(..) => "Header",
70            HttpTask::Body(..) => "Body",
71            HttpTask::UpgradedBody(..) => "UpgradedBody",
72            HttpTask::Trailer(_) => "Trailer",
73            HttpTask::Done => "Done",
74            HttpTask::Failed(_) => "Failed",
75        }
76    }
77}