pingora_core/protocols/http/mod.rs
1// Copyright 2025 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
17mod body_buffer;
18pub mod bridge;
19pub mod client;
20pub mod compression;
21pub mod conditional_filter;
22pub(crate) mod date;
23pub mod error_resp;
24pub mod server;
25pub mod v1;
26pub mod v2;
27
28pub use server::Session as ServerSession;
29
30/// The Pingora server name string
31pub const SERVER_NAME: &[u8; 7] = b"Pingora";
32
33/// An enum to hold all possible HTTP response events.
34#[derive(Debug)]
35pub enum HttpTask {
36 /// the response header and the boolean end of response flag
37 Header(Box<pingora_http::ResponseHeader>, bool),
38 /// A piece of response body and the end of response boolean flag
39 Body(Option<bytes::Bytes>, bool),
40 /// HTTP response trailer
41 Trailer(Option<Box<http::HeaderMap>>),
42 /// Signal that the response is already finished
43 Done,
44 /// Signal that the reading of the response encountered errors.
45 Failed(pingora_error::BError),
46}
47
48impl HttpTask {
49 /// Whether this [`HttpTask`] means the end of the response
50 pub fn is_end(&self) -> bool {
51 match self {
52 HttpTask::Header(_, end) => *end,
53 HttpTask::Body(_, end) => *end,
54 HttpTask::Trailer(_) => true,
55 HttpTask::Done => true,
56 HttpTask::Failed(_) => true,
57 }
58 }
59}