Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
taikulawo committed Jul 10, 2024
1 parent 168b52d commit 07a4916
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions pingora-proxy/examples/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use clap::Parser;
use log::info;
use std::sync::Mutex;

use pingora_core::{protocols::http::ServerSession, server::configuration::Opt};
use pingora_core::server::configuration::Opt;
use pingora_core::server::Server;
use pingora_core::upstreams::peer::HttpPeer;
use pingora_core::Result;
Expand All @@ -43,7 +43,7 @@ fn check_beta_user(req: &pingora_http::RequestHeader) -> bool {
#[async_trait]
impl ProxyHttp for MyProxy {
type CTX = MyCtx;
fn new_ctx(&self, session: &Box<ServerSession>) -> Self::CTX {
fn new_ctx(&self, session: &Session) -> Self::CTX {
MyCtx { beta_user: false }
}

Expand Down
4 changes: 2 additions & 2 deletions pingora-proxy/examples/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use clap::Parser;
use log::info;
use prometheus::register_int_counter;

use pingora_core::server::configuration::Opt;
use pingora_core::server::Server;
use pingora_core::upstreams::peer::HttpPeer;
use pingora_core::Result;
use pingora_core::{protocols::http::ServerSession, server::configuration::Opt};
use pingora_http::ResponseHeader;
use pingora_proxy::{ProxyHttp, Session};

Expand All @@ -36,7 +36,7 @@ pub struct MyGateway {
#[async_trait]
impl ProxyHttp for MyGateway {
type CTX = ();
fn new_ctx(&self, _session: &Box<ServerSession>) -> Self::CTX {}
fn new_ctx(&self, _session: &Session) -> Self::CTX {}

async fn request_filter(&self, session: &mut Session, _ctx: &mut Self::CTX) -> Result<bool> {
if session.req_header().uri.path().starts_with("/login")
Expand Down
4 changes: 2 additions & 2 deletions pingora-proxy/examples/load_balancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use async_trait::async_trait;
use clap::Parser;
use log::info;
use pingora_core::{protocols::http::ServerSession, services::background::background_service};
use pingora_core::services::background::background_service;
use std::{sync::Arc, time::Duration};

use pingora_core::server::configuration::Opt;
Expand All @@ -30,7 +30,7 @@ pub struct LB(Arc<LoadBalancer<RoundRobin>>);
#[async_trait]
impl ProxyHttp for LB {
type CTX = ();
fn new_ctx(&self, _session: &Box<ServerSession>) -> Self::CTX {}
fn new_ctx(&self, _session: &Session) -> Self::CTX {}

async fn upstream_peer(&self, _session: &mut Session, _ctx: &mut ()) -> Result<Box<HttpPeer>> {
let upstream = self
Expand Down
4 changes: 2 additions & 2 deletions pingora-proxy/examples/modify_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ use clap::Parser;
use serde::{Deserialize, Serialize};
use std::net::ToSocketAddrs;

use pingora_core::server::configuration::Opt;
use pingora_core::server::Server;
use pingora_core::upstreams::peer::HttpPeer;
use pingora_core::Result;
use pingora_core::{protocols::http::ServerSession, server::configuration::Opt};
use pingora_http::ResponseHeader;
use pingora_proxy::{ProxyHttp, Session};

Expand All @@ -43,7 +43,7 @@ pub struct MyCtx {
#[async_trait]
impl ProxyHttp for Json2Yaml {
type CTX = MyCtx;
fn new_ctx(&self, _session: &Box<ServerSession>) -> Self::CTX {
fn new_ctx(&self, _session: &Session) -> Self::CTX {
MyCtx { buffer: vec![] }
}

Expand Down
4 changes: 2 additions & 2 deletions pingora-proxy/examples/multi_lb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use async_trait::async_trait;
use std::sync::Arc;

use pingora_core::{prelude::*, protocols::http::ServerSession, services::background::GenBackgroundService};
use pingora_core::{prelude::*, services::background::GenBackgroundService};
use pingora_load_balancing::{
health_check::TcpHealthCheck,
selection::{BackendIter, BackendSelection, RoundRobin},
Expand All @@ -31,7 +31,7 @@ struct Router {
#[async_trait]
impl ProxyHttp for Router {
type CTX = ();
fn new_ctx(&self, _session: &Box<ServerSession>) {}
fn new_ctx(&self, _session: &Session) {}

async fn upstream_peer(&self, session: &mut Session, _ctx: &mut ()) -> Result<Box<HttpPeer>> {
// determine LB cluster based on request uri
Expand Down
12 changes: 6 additions & 6 deletions pingora-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,17 +680,17 @@ where
sub_req_ctx: Box<SubReqCtx>,
) {
debug!("starting subrequest");
let ctx = self.inner.new_ctx(&session);
let mut session = match self.handle_new_request(session).await {
Some(downstream_session) => Session::new(downstream_session, &self.downstream_modules),
None => return, // bad request
};

// no real downstream to keepalive, but it doesn't matter what is set here because at the end
// of this fn the dummy connection will be dropped
session.set_keepalive(None);

session.subrequest_ctx.replace(sub_req_ctx);
let ctx = self.inner.new_ctx(&session);
trace!("processing subrequest");
self.process_request(session, ctx).await;
trace!("subrequest done");
Expand All @@ -709,21 +709,21 @@ where
shutdown: &ShutdownWatch,
) -> Option<Stream> {
let session = Box::new(session);
let ctx = self.inner.new_ctx(&session);
// TODO: keepalive pool, use stack
let mut session = match self.handle_new_request(session).await {
Some(downstream_session) => Session::new(downstream_session, &self.downstream_modules),
None => return None, // bad request
};

if *shutdown.borrow() {
// stop downstream from reusing if this service is shutting down soon
session.set_keepalive(None);
} else {
// default 60s
session.set_keepalive(Some(60));
}


let ctx = self.inner.new_ctx(&session);
self.process_request(session, ctx).await
}

Expand Down
2 changes: 1 addition & 1 deletion pingora-proxy/src/proxy_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait ProxyHttp {
type CTX;

/// Define how the `ctx` should be created.
fn new_ctx(&self, session: &Box<HttpSession>) -> Self::CTX;
fn new_ctx(&self, session: &Session) -> Self::CTX;

/// Define where the proxy should send the request to.
///
Expand Down
6 changes: 3 additions & 3 deletions pingora-proxy/tests/utils/server_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn response_filter_common(
#[async_trait]
impl ProxyHttp for ExampleProxyHttps {
type CTX = CTX;
fn new_ctx(&self, session: &Box<ServerSession>) -> Self::CTX {
fn new_ctx(&self, session: &Session) -> Self::CTX {
CTX::default()
}

Expand Down Expand Up @@ -207,7 +207,7 @@ pub struct ExampleProxyHttp {}
#[async_trait]
impl ProxyHttp for ExampleProxyHttp {
type CTX = CTX;
fn new_ctx(&self, session: &Box<ServerSession>) -> Self::CTX {
fn new_ctx(&self, session: &Session) -> Self::CTX {
CTX::default()
}

Expand Down Expand Up @@ -340,7 +340,7 @@ pub struct ExampleProxyCache {}
#[async_trait]
impl ProxyHttp for ExampleProxyCache {
type CTX = CacheCTX;
fn new_ctx(&self, session: &Box<ServerSession>) -> Self::CTX {
fn new_ctx(&self, session: &Session) -> Self::CTX {
CacheCTX {
upstream_status: None,
}
Expand Down

0 comments on commit 07a4916

Please sign in to comment.