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 response body and the end of response boolean flag
41 Body(Option<bytes::Bytes>, bool),
42 /// HTTP response trailer
43 Trailer(Option<Box<http::HeaderMap>>),
44 /// Signal that the response is already finished
45 Done,
46 /// Signal that the reading of the response encountered errors.
47 Failed(pingora_error::BError),
48}
49
50impl HttpTask {
51 /// Whether this [`HttpTask`] means the end of the response.
52 pub fn is_end(&self) -> bool {
53 match self {
54 HttpTask::Header(_, end) => *end,
55 HttpTask::Body(_, end) => *end,
56 HttpTask::Trailer(_) => true,
57 HttpTask::Done => true,
58 HttpTask::Failed(_) => true,
59 }
60 }
61
62 /// The [`HttpTask`] type as string.
63 pub fn type_str(&self) -> &'static str {
64 match self {
65 HttpTask::Header(..) => "Header",
66 HttpTask::Body(..) => "Body",
67 HttpTask::Trailer(_) => "Trailer",
68 HttpTask::Done => "Done",
69 HttpTask::Failed(_) => "Failed",
70 }
71 }
72}