Skip to main content

praxis_protocol/http/pingora/
mod.rs

1// SPDX-License-Identifier: MIT
2// Copyright (c) 2024 Praxis Contributors
3
4//! Pingora HTTP integration: handler, listener setup, health endpoints.
5
6use std::sync::Arc;
7
8use praxis_core::{
9    PingoraServerRuntime, ProxyError,
10    config::{Config, ProtocolKind},
11};
12
13use crate::{ListenerPipelines, Protocol};
14
15/// Per-request context for filter pipeline results.
16pub mod context;
17pub(crate) mod convert;
18/// HTTP proxy handler and Pingora integration.
19pub mod handler;
20/// Health check infrastructure: admin endpoints, probes, and background runner.
21pub mod health;
22pub(crate) mod json;
23/// Admin endpoints for runtime key-value store CRUD.
24pub mod kv;
25/// Listener configuration and TLS setup.
26pub mod listener;
27/// Prometheus metrics: recorder, HTTP request counters, and scrape endpoint.
28pub mod metrics;
29
30// -----------------------------------------------------------------------------
31// PingoraHttp
32// -----------------------------------------------------------------------------
33
34/// Pingora-backed HTTP protocol implementation.
35pub struct PingoraHttp;
36
37impl Protocol for PingoraHttp {
38    fn register(
39        self: Box<Self>,
40        server: &mut PingoraServerRuntime,
41        config: &Config,
42        pipelines: &ListenerPipelines,
43    ) -> Result<Vec<tokio::sync::watch::Sender<bool>>, ProxyError> {
44        let http_listeners: Vec<_> = config
45            .listeners
46            .iter()
47            .filter(|l| l.protocol == ProtocolKind::Http)
48            .collect();
49
50        if http_listeners.is_empty() {
51            return Ok(Vec::new());
52        }
53
54        let mut cert_watcher_shutdowns = Vec::new();
55        for listener in &http_listeners {
56            let pipeline = pipelines.get(&listener.name).map(Arc::clone).ok_or_else(|| {
57                ProxyError::Config(format!("no pipeline for listener '{name}'", name = listener.name))
58            })?;
59
60            handler::load_http_handler(server.server_mut(), listener, pipeline, &mut cert_watcher_shutdowns)?;
61        }
62
63        Ok(cert_watcher_shutdowns)
64    }
65}