From 34c67f0acae52ce94a3a6d5696e0847e63b42be7 Mon Sep 17 00:00:00 2001 From: spacewander Date: Sat, 31 Aug 2024 01:38:05 +0800 Subject: [PATCH 1/2] document early_request_filter Fix #363 Signed-off-by: spacewander --- docs/user_guide/phase.md | 8 ++++++-- docs/user_guide/phase_chart.md | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/user_guide/phase.md b/docs/user_guide/phase.md index a32649685..5e30db88c 100644 --- a/docs/user_guide/phase.md +++ b/docs/user_guide/phase.md @@ -16,7 +16,8 @@ The pingora-proxy HTTP proxy framework supports highly programmable proxy behavi Pingora-proxy allows users to insert arbitrary logic into the life of a request. ```mermaid graph TD; - start("new request")-->request_filter; + start("new request")-->early_request_filter; + early_request_filter-->request_filter; request_filter-->upstream_peer; upstream_peer-->Connect{{IO: connect to upstream}}; @@ -52,9 +53,12 @@ Pingora-proxy allows users to insert arbitrary logic into the life of a request. * The reason both `upstream_response_*_filter()` and `response_*_filter()` exist is for HTTP caching integration reasons (still WIP). -### `request_filter()` +### `early_request_filter()` This is the first phase of every request. +This function is similar to `request_filter()` but execute before any other logic especially the downstream modules. + +### `request_filter()` This phase is usually for validating request inputs, rate limiting, and initializing context. ### `proxy_upstream_filter()` diff --git a/docs/user_guide/phase_chart.md b/docs/user_guide/phase_chart.md index a7d01d433..a6b6a4e19 100644 --- a/docs/user_guide/phase_chart.md +++ b/docs/user_guide/phase_chart.md @@ -1,7 +1,8 @@ Pingora proxy phases without caching ```mermaid graph TD; - start("new request")-->request_filter; + start("new request")-->early_request_filter; + early_request_filter-->request_filter; request_filter-->upstream_peer; upstream_peer-->Connect{{IO: connect to upstream}}; From 204ddb02743445e6204858b4df3ea3f28fa1911c Mon Sep 17 00:00:00 2001 From: spacewander Date: Mon, 2 Sep 2024 21:57:21 +0800 Subject: [PATCH 2/2] updated Signed-off-by: spacewander --- docs/user_guide/phase.md | 2 +- pingora-proxy/src/proxy_trait.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/user_guide/phase.md b/docs/user_guide/phase.md index 5e30db88c..46e9b5db7 100644 --- a/docs/user_guide/phase.md +++ b/docs/user_guide/phase.md @@ -56,7 +56,7 @@ Pingora-proxy allows users to insert arbitrary logic into the life of a request. ### `early_request_filter()` This is the first phase of every request. -This function is similar to `request_filter()` but execute before any other logic especially the downstream modules. +This function is similar to `request_filter()` but executes before any other logic, including downstream module logic. The main purpose of this function is to provide finer-grained control of the behavior of the modules. ### `request_filter()` This phase is usually for validating request inputs, rate limiting, and initializing context. diff --git a/pingora-proxy/src/proxy_trait.rs b/pingora-proxy/src/proxy_trait.rs index 2d99567eb..029ea58f0 100644 --- a/pingora-proxy/src/proxy_trait.rs +++ b/pingora-proxy/src/proxy_trait.rs @@ -69,9 +69,9 @@ pub trait ProxyHttp { /// Handle the incoming request before any downstream module is executed. /// - /// This function is similar to [Self::request_filter()] but execute before any other logic - /// especially the downstream modules. The main purpose of this function is to provide finer - /// grained control of behavior of the modules. + /// This function is similar to [Self::request_filter()] but executes before any other logic, + /// including downstream module logic. The main purpose of this function is to provide finer + /// grained control of the behavior of the modules. /// /// Note that because this function is executed before any module that might provide access /// control or rate limiting, logic should stay in request_filter() if it can in order to be