-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
session.respond_error with custom headers #381
Comments
One option is to reuse your response filter logic to modify the response header from In the phase chart you'll notice this is currently by design, a bit different from how nginx might work. The response filter will get called for upstream or cached responses, but writing the response header directly short circuits the state machine. |
@drcaramelsyrup Thanks!!! I did it use pingora_core::protocols::http::ServerSession as HttpSession;
async fn show_error(session: &mut Session, error: u16) -> Result<()> {
let mut resp = HttpSession::generate_error(error);
resp.insert_header("X-Error-Type", "Internal");
resp.insert_header("X-Error-From", "Lib-xxxxxx");
session.write_response_header(Box::new(resp), true)
.await
.unwrap_or_else(|e| {
session.downstream_session.set_keepalive(None);
error!("failed to send error response to downstream: {e}");
});
Ok(())
} It's good if it comes with a message. |
Great!
Do you mean there's some enhancement we could make to our docs? It would be helpful to know what that would look like. |
Just add body content (ex: html) |
What is the problem your feature solves, or the need it fulfills?
response_filter was not call after throw error by session.respond_error
Additional context
Please add solution for this
The text was updated successfully, but these errors were encountered: