diff options
author | Andrew Hauck <[email protected]> | 2024-11-08 14:34:14 -0800 |
---|---|---|
committer | Yuchen Wu <[email protected]> | 2024-12-13 17:27:40 -0800 |
commit | a8a6e77eef2c0f4d2a45f00c5b0e316dd373f2f2 (patch) | |
tree | c5eb5e7b4e8b4c267de63f1c338365a09847a584 /pingora-proxy/examples | |
parent | e309436319ed5cbc3aaf53221070a1fd070b8bcf (diff) | |
download | pingora-a8a6e77eef2c0f4d2a45f00c5b0e316dd373f2f2.tar.gz pingora-a8a6e77eef2c0f4d2a45f00c5b0e316dd373f2f2.zip |
Improve support for sending custom response headers and bodies for error messages
Diffstat (limited to 'pingora-proxy/examples')
-rw-r--r-- | pingora-proxy/examples/gateway.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/pingora-proxy/examples/gateway.rs b/pingora-proxy/examples/gateway.rs index 78f4aae..d4a5cee 100644 --- a/pingora-proxy/examples/gateway.rs +++ b/pingora-proxy/examples/gateway.rs @@ -13,6 +13,7 @@ // limitations under the License. use async_trait::async_trait; +use bytes::Bytes; use clap::Parser; use log::info; use prometheus::register_int_counter; @@ -42,7 +43,9 @@ impl ProxyHttp for MyGateway { if session.req_header().uri.path().starts_with("/login") && !check_login(session.req_header()) { - let _ = session.respond_error(403).await; + let _ = session + .respond_error_with_body(403, Bytes::from_static(b"no way!")) + .await; // true: early return as the response is already written return Ok(true); } @@ -103,7 +106,7 @@ impl ProxyHttp for MyGateway { } } -// RUST_LOG=INFO cargo run --example load_balancer +// RUST_LOG=INFO cargo run --example gateway // curl 127.0.0.1:6191 -H "Host: one.one.one.one" // curl 127.0.0.1:6190/family/ -H "Host: one.one.one.one" // curl 127.0.0.1:6191/login/ -H "Host: one.one.one.one" -I -H "Authorization: password" |