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