Closed Maydisease closed 3 weeks ago
You can use session.respond_error
like this:
https://github.com/cloudflare/pingora/blob/main/pingora-proxy/examples/gateway.rs#L42
You can use
session.respond_error
like this:https://github.com/cloudflare/pingora/blob/main/pingora-proxy/examples/gateway.rs#L42
If I want to return a status code of 200 and customize the body, can this be achieved?
session.write_response_header(Box::new(header)).await?;
session.write_response_body(body).await?;
`
async fn request_filter(&self, session: &mut Session, ctx: &mut Self::CTX) -> Result
let req_header = session.req_header();
let uri = format!("{}", req_header.uri);
let mut pathname = String::new();
if uri.starts_with("https://") || uri.starts_with("http://") {
let http_url = lib::utils::parse_url(&uri).unwrap();
pathname = http_url.pathname;
} else {
pathname = req_header.uri.to_string();
}
if req_header.method == "POST" && pathname.starts_with("/__private_api") {
let person = Person {
name: "Alice".to_string(),
age: 30,
city: "Wonderland".to_string(),
};
let req_body = session.read_request_body().await?;
println!("req_body: {}", String::from_utf8(Vec::from(req_body.unwrap())).unwrap());
let body: Bytes = Bytes::from(serde_json::to_string(&person).unwrap());
let mut header = ResponseHeader::build(200, None).unwrap();
header.append_header("Content-Type", "application/json").unwrap();
session.write_response_header(Box::new(header)).await?;
session.write_response_body(body).await?;
println!("echo result");
return Ok(true);
}
Ok(false)
}
` I attempted to send content to the client, but it seems to have been intercepted directly, resulting in a client timeout. How can I resolve this issue?
content-length: body_size
and session.finish_body().await?
transfer-encoding: chunked
and session.finish_body().await?
content-length: body_size
andsession.finish_body().await?
- chunked response
transfer-encoding: chunked
andsession.finish_body().await?
Thank you, it worked. Thanks again.
This question has been stale for a week. It will be closed in an additional day if not updated.
This issue has been closed because it has been stalled with no activity.
I would like to implement the following functionality:
Act as a proxy server. When I match an endpoint that starts with /__api, do not proxy the request and return an error to the client. How can I achieve this?