Skip to content

Commit

Permalink
report to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
taikulawo committed Jul 16, 2024
1 parent 38a9d55 commit 25d95e4
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pingora-core/src/protocols/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl ALPN {
}
}

pub(crate) fn from_wire_selected(raw: &[u8]) -> Option<Self> {
pub fn from_wire_selected(raw: &[u8]) -> Option<Self> {
match raw {
b"http/1.1" => Some(Self::H1),
b"h2" => Some(Self::H2),
Expand Down
2 changes: 1 addition & 1 deletion pingora-proxy/examples/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> Self::CTX {
fn new_ctx(&self, _session: &Session) -> Self::CTX {
MyCtx { beta_user: false }
}

Expand Down
2 changes: 1 addition & 1 deletion pingora-proxy/examples/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct MyGateway {
#[async_trait]
impl ProxyHttp for MyGateway {
type CTX = ();
fn new_ctx(&self) -> 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
2 changes: 1 addition & 1 deletion pingora-proxy/examples/load_balancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct LB(Arc<LoadBalancer<RoundRobin>>);
#[async_trait]
impl ProxyHttp for LB {
type CTX = ();
fn new_ctx(&self) -> 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
2 changes: 1 addition & 1 deletion pingora-proxy/examples/modify_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct MyCtx {
#[async_trait]
impl ProxyHttp for Json2Yaml {
type CTX = MyCtx;
fn new_ctx(&self) -> Self::CTX {
fn new_ctx(&self, _session: &Session) -> Self::CTX {
MyCtx { buffer: vec![] }
}

Expand Down
2 changes: 1 addition & 1 deletion pingora-proxy/examples/multi_lb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Router {
#[async_trait]
impl ProxyHttp for Router {
type CTX = ();
fn new_ctx(&self) {}
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
7 changes: 3 additions & 4 deletions pingora-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub struct HttpProxy<SV> {
}

impl<SV> HttpProxy<SV> {
fn new(inner: SV, conf: Arc<ServerConf>) -> Self {
pub fn new(inner: SV, conf: Arc<ServerConf>) -> Self {
HttpProxy {
inner,
client_upstream: Connector::new(Some(ConnectorOptions::from_server_conf(&conf))),
Expand Down Expand Up @@ -690,8 +690,8 @@ where
session.set_keepalive(None);

session.subrequest_ctx.replace(sub_req_ctx);
let ctx = self.inner.new_ctx(&session);
trace!("processing subrequest");
let ctx = self.inner.new_ctx();
self.process_request(session, ctx).await;
trace!("subrequest done");
}
Expand All @@ -709,7 +709,6 @@ where
shutdown: &ShutdownWatch,
) -> Option<Stream> {
let session = Box::new(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),
Expand All @@ -724,7 +723,7 @@ where
session.set_keepalive(Some(60));
}

let ctx = self.inner.new_ctx();
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) -> Self::CTX;
fn new_ctx(&self, session: &Session) -> Self::CTX;

/// Define where the proxy should send the request to.
///
Expand Down
8 changes: 5 additions & 3 deletions pingora-proxy/tests/utils/server_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use pingora_cache::{
};
use pingora_core::apps::{HttpServerApp, HttpServerOptions};
use pingora_core::modules::http::compression::ResponseCompression;
use pingora_core::protocols::http::client::HttpSession;
use pingora_core::protocols::http::ServerSession;
use pingora_core::protocols::{l4::socket::SocketAddr, Digest};
use pingora_core::server::configuration::Opt;
use pingora_core::services::Service;
Expand Down Expand Up @@ -108,7 +110,7 @@ fn response_filter_common(
#[async_trait]
impl ProxyHttp for ExampleProxyHttps {
type CTX = CTX;
fn new_ctx(&self) -> Self::CTX {
fn new_ctx(&self, session: &Session) -> Self::CTX {
CTX::default()
}

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

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

0 comments on commit 25d95e4

Please sign in to comment.